1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/
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.
13
* The Original Code is mozilla.org code.
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
25
#include "nsIServiceManager.h"
28
#include "nsDeviceContextMac.h"
30
#include "nsFontUtils.h"
32
PRBool nsFontUtils::sDisplayVerySmallFonts = true;
36
nsFontUtils::DisplayVerySmallFonts()
38
static PRBool sInitialized = PR_FALSE;
40
return sDisplayVerySmallFonts;
42
sInitialized = PR_TRUE;
45
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
46
if (NS_SUCCEEDED(rv) && prefs) {
48
if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display_very_small_fonts", &boolVal))) {
49
sDisplayVerySmallFonts = boolVal;
53
return sDisplayVerySmallFonts;
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.
61
nsFontUtils::GetNativeTextStyle(nsIFontMetrics& inMetrics,
62
const nsIDeviceContext& inDevContext, TextStyle &outStyle)
66
inMetrics.GetFont(aFont);
69
inMetrics.GetFontHandle(fontNum);
72
dev2app = inDevContext.DevUnitsToAppUnits();
73
short textSize = float(aFont->size) / dev2app;
75
if (textSize < 9 && !nsFontUtils::DisplayVerySmallFonts())
78
Style textFace = normal;
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
86
PRInt32 offset = aFont->weight % 100;
87
PRInt32 baseWeight = aFont->weight / 100;
88
NS_ASSERTION((offset < 10) || (offset > 90), "Invalid bolder or lighter value");
90
if (aFont->weight >= NS_FONT_WEIGHT_BOLD)
99
outStyle.tsFont = (short)fontNum;
100
outStyle.tsFace = textFace;
101
outStyle.tsSize = textSize;
102
outStyle.tsColor = black;