Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / gfx / src / thebes / nsSystemFontsBeOS.cpp
blob258dee07280d74dc0fc4dcd3961de6bb0c200e2d
1 /* vim: set sw=2 sts=2 et cin: */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is BeOS system font code in Thebes.
17 * The Initial Developer of the Original Code is
18 * Christian Biesinger <cbiesinger@web.de>.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Parts of this file used to live in nsDeviceContextBeos.cpp. The Original
24 * Author of that code is Netscape Communications Corporation.
26 * Pierre Phaneuf <pp@ludusdesign.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #include <Font.h>
43 #include <Menu.h>
45 #include "nsIDeviceContext.h"
46 #include "nsSystemFontsBeOS.h"
48 nsSystemFontsBeOS::nsSystemFontsBeOS()
49 : mDefaultFontName(NS_LITERAL_STRING("sans-serif"))
50 , mMenuFontName(NS_LITERAL_STRING("sans-serif"))
51 , mCaptionFontName(NS_LITERAL_STRING("sans-serif"))
53 menu_info info;
54 get_menu_info(&info);
55 BFont menuFont;
56 menuFont.SetFamilyAndStyle(info.f_family, info.f_style);
57 menuFont.SetSize(info.font_size);
59 GetSystemFontInfo(be_plain_font, &mDefaultFontName, &mDefaultFontStyle);
60 GetSystemFontInfo(be_bold_font, &mCaptionFontName, &mCaptionFontStyle);
61 GetSystemFontInfo(&menuFont, &mMenuFontName, &mMenuFontStyle);
64 nsresult nsSystemFontsBeOS::GetSystemFont(nsSystemFontID aID,
65 nsString *aFontName,
66 gfxFontStyle *aFontStyle) const
68 switch (aID) {
69 case eSystemFont_PullDownMenu:
70 case eSystemFont_Menu:
71 *aFontName = mMenuFontName;
72 *aFontStyle = mMenuFontStyle;
73 return NS_OK;
74 case eSystemFont_Caption: // css2 bold
75 *aFontName = mCaptionFontName;
76 *aFontStyle = mCaptionFontStyle;
77 return NS_OK;
78 case eSystemFont_List:
79 case eSystemFont_Field:
80 case eSystemFont_Icon :
81 case eSystemFont_MessageBox :
82 case eSystemFont_SmallCaption :
83 case eSystemFont_StatusBar :
84 case eSystemFont_Window: // css3
85 case eSystemFont_Document:
86 case eSystemFont_Workspace:
87 case eSystemFont_Desktop:
88 case eSystemFont_Info:
89 case eSystemFont_Dialog:
90 case eSystemFont_Button:
91 case eSystemFont_Tooltips: // moz
92 case eSystemFont_Widget:
93 default:
94 *aFontName = mDefaultFontName;
95 *aFontStyle = mDefaultFontStyle;
96 return NS_OK;
98 NS_NOTREACHED("huh?");
101 nsresult
102 nsSystemFontsBeOS::GetSystemFontInfo(const BFont *theFont, nsString *aFontName,
103 gfxFontStyle *aFontStyle) const
106 aFontStyle->style = FONT_STYLE_NORMAL;
107 aFontStyle->weight = FONT_WEIGHT_NORMAL;
108 aFontStyle->decorations = FONT_DECORATION_NONE;
110 font_family family;
111 theFont->GetFamilyAndStyle(&family, NULL);
113 uint16 face = theFont->Face();
114 CopyUTF8toUTF16(family, *aFontName);
115 aFontStyle->size = theFont->Size();
117 if (face & B_ITALIC_FACE)
118 aFontStyle->style = FONT_STYLE_ITALIC;
120 if (face & B_BOLD_FACE)
121 aFontStyle->weight = FONT_WEIGHT_BOLD;
123 if (face & B_UNDERSCORE_FACE)
124 aFontStyle->decorations |= FONT_DECORATION_UNDERLINE;
126 if (face & B_STRIKEOUT_FACE)
127 aFontStyle->decorations |= FONT_DECORATION_STRIKEOUT;
129 aFontStyle->systemFont = PR_TRUE;
131 return NS_OK;