~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gfx/src/mac/nsFontUtils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
 *
 
3
 * The contents of this file are subject to the Netscape Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is mozilla.org code.
 
14
 *
 
15
 * The Initial Developer of the Original Code is Netscape
 
16
 * Communications Corporation.  Portions created by Netscape are
 
17
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
18
 * Rights Reserved.
 
19
 *
 
20
 * Contributor(s): 
 
21
 */
 
22
 
 
23
 
 
24
#include "nsIPref.h"
 
25
#include "nsIServiceManager.h"
 
26
 
 
27
#include "nsFont.h"
 
28
#include "nsDeviceContextMac.h"
 
29
 
 
30
#include "nsFontUtils.h"
 
31
 
 
32
PRBool nsFontUtils::sDisplayVerySmallFonts = true;
 
33
 
 
34
 
 
35
PRBool
 
36
nsFontUtils::DisplayVerySmallFonts()
 
37
{
 
38
        static PRBool sInitialized = PR_FALSE;
 
39
        if (sInitialized)
 
40
                return sDisplayVerySmallFonts;
 
41
 
 
42
        sInitialized = PR_TRUE;
 
43
 
 
44
  nsresult rv;
 
45
  nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
 
46
  if (NS_SUCCEEDED(rv) && prefs) {
 
47
    PRBool boolVal;
 
48
    if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display_very_small_fonts", &boolVal))) {
 
49
      sDisplayVerySmallFonts = boolVal;
 
50
    }
 
51
  }
 
52
 
 
53
        return sDisplayVerySmallFonts;
 
54
}
 
55
 
 
56
 
 
57
// A utility routine to the the text style in a convenient manner.
 
58
// This is static, which is unfortunate, because it introduces link
 
59
// dependencies between libraries that should not exist.
 
60
void
 
61
nsFontUtils::GetNativeTextStyle(nsIFontMetrics& inMetrics,
 
62
                const nsIDeviceContext& inDevContext, TextStyle &outStyle)
 
63
{
 
64
        
 
65
        const nsFont *aFont;
 
66
        inMetrics.GetFont(aFont);
 
67
        
 
68
        nsFontHandle    fontNum;
 
69
        inMetrics.GetFontHandle(fontNum);
 
70
        
 
71
        float  dev2app;
 
72
        dev2app = inDevContext.DevUnitsToAppUnits();
 
73
        short           textSize = float(aFont->size) / dev2app;
 
74
 
 
75
        if (textSize < 9 && !nsFontUtils::DisplayVerySmallFonts())
 
76
                textSize = 9;
 
77
        
 
78
        Style textFace = normal;
 
79
        switch (aFont->style)
 
80
        {
 
81
                case NS_FONT_STYLE_NORMAL:                                                              break;
 
82
                case NS_FONT_STYLE_ITALIC:              textFace |= italic;             break;
 
83
                case NS_FONT_STYLE_OBLIQUE:     textFace |= italic;             break;  //XXX
 
84
        }
 
85
 
 
86
        PRInt32 offset = aFont->weight % 100;
 
87
        PRInt32 baseWeight = aFont->weight / 100;
 
88
        NS_ASSERTION((offset < 10) || (offset > 90), "Invalid bolder or lighter value");
 
89
        if (offset == 0) {
 
90
                if (aFont->weight >= NS_FONT_WEIGHT_BOLD)
 
91
                        textFace |= bold;
 
92
        } else {
 
93
                if (offset < 10)
 
94
                        textFace |= bold;
 
95
        }
 
96
 
 
97
        RGBColor        black = {0};
 
98
 
 
99
        outStyle.tsFont = (short)fontNum;
 
100
        outStyle.tsFace = textFace;
 
101
        outStyle.tsSize = textSize;
 
102
        outStyle.tsColor = black;
 
103
}
 
104