Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / gfx / thebes / public / gfxPlatform.h
blobdd9b7836fcb86dd54a6884acad0c3925db098e40
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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 Mozilla Foundation code.
17 * The Initial Developer of the Original Code is Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2005
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Vladimir Vukicevic <vladimir@pobox.com>
23 * Masayuki Nakano <masayuki@d-toybox.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef GFX_PLATFORM_H
40 #define GFX_PLATFORM_H
42 #include "prtypes.h"
43 #include "nsVoidArray.h"
45 #include "nsIObserver.h"
47 #include "gfxTypes.h"
48 #include "gfxASurface.h"
49 #include "gfxColor.h"
51 #ifdef XP_OS2
52 #undef OS2EMX_PLAIN_CHAR
53 #endif
55 typedef void* cmsHPROFILE;
56 typedef void* cmsHTRANSFORM;
58 class gfxImageSurface;
59 class gfxFont;
60 class gfxFontGroup;
61 struct gfxFontStyle;
62 class gfxUserFontSet;
63 class gfxFontEntry;
64 class nsIURI;
66 // pref lang id's for font prefs
67 // !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
69 enum eFontPrefLang {
70 eFontPrefLang_Western = 0,
71 eFontPrefLang_CentEuro = 1,
72 eFontPrefLang_Japanese = 2,
73 eFontPrefLang_ChineseTW = 3,
74 eFontPrefLang_ChineseCN = 4,
75 eFontPrefLang_ChineseHK = 5,
76 eFontPrefLang_Korean = 6,
77 eFontPrefLang_Cyrillic = 7,
78 eFontPrefLang_Baltic = 8,
79 eFontPrefLang_Greek = 9,
80 eFontPrefLang_Turkish = 10,
81 eFontPrefLang_Thai = 11,
82 eFontPrefLang_Hebrew = 12,
83 eFontPrefLang_Arabic = 13,
84 eFontPrefLang_Devanagari = 14,
85 eFontPrefLang_Tamil = 15,
86 eFontPrefLang_Armenian = 16,
87 eFontPrefLang_Bengali = 17,
88 eFontPrefLang_Canadian = 18,
89 eFontPrefLang_Ethiopic = 19,
90 eFontPrefLang_Georgian = 20,
91 eFontPrefLang_Gujarati = 21,
92 eFontPrefLang_Gurmukhi = 22,
93 eFontPrefLang_Khmer = 23,
94 eFontPrefLang_Malayalam = 24,
95 eFontPrefLang_Oriya = 25,
96 eFontPrefLang_Telugu = 26,
97 eFontPrefLang_Kannada = 27,
98 eFontPrefLang_Sinhala = 28,
100 eFontPrefLang_LangCount = 29, // except Others and UserDefined.
102 eFontPrefLang_Others = 29, // x-unicode
103 eFontPrefLang_UserDefined = 30,
105 eFontPrefLang_CJKSet = 31, // special code for CJK set
106 eFontPrefLang_AllCount = 32
109 enum eCMSMode {
110 eCMSMode_Off = 0, // No color management
111 eCMSMode_All = 1, // Color manage everything
112 eCMSMode_TaggedOnly = 2, // Color manage tagged Images Only
113 eCMSMode_AllCount = 3
116 // when searching through pref langs, max number of pref langs
117 const PRUint32 kMaxLenPrefLangList = 32;
119 class THEBES_API gfxPlatform {
120 public:
122 * Return a pointer to the current active platform.
123 * This is a singleton; it contains mostly convenience
124 * functions to obtain platform-specific objects.
126 static gfxPlatform *GetPlatform();
129 * Start up Thebes. This can fail.
131 static nsresult Init();
134 * Clean up static objects to shut down thebes.
136 static void Shutdown();
139 * Create an offscreen surface of the given dimensions
140 * and image format.
142 virtual already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
143 gfxASurface::gfxImageFormat imageFormat) = 0;
146 virtual already_AddRefed<gfxASurface> OptimizeImage(gfxImageSurface *aSurface,
147 gfxASurface::gfxImageFormat format);
150 * Font bits
154 * Fill aListOfFonts with the results of querying the list of font names
155 * that correspond to the given language group or generic font family
156 * (or both, or neither).
158 virtual nsresult GetFontList(const nsACString& aLangGroup,
159 const nsACString& aGenericFamily,
160 nsStringArray& aListOfFonts);
163 * Rebuilds the any cached system font lists
165 virtual nsresult UpdateFontList();
168 * Font name resolver, this returns actual font name(s) by the callback
169 * function. If the font doesn't exist, the callback function is not called.
170 * If the callback function returns PR_FALSE, the aAborted value is set to
171 * PR_TRUE, otherwise, PR_FALSE.
173 typedef PRBool (*FontResolverCallback) (const nsAString& aName,
174 void *aClosure);
175 virtual nsresult ResolveFontName(const nsAString& aFontName,
176 FontResolverCallback aCallback,
177 void *aClosure,
178 PRBool& aAborted) = 0;
181 * Resolving a font name to family name. The result MUST be in the result of GetFontList().
182 * If the name doesn't in the system, aFamilyName will be empty string, but not failed.
184 virtual nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) = 0;
187 * Create the appropriate platform font group
189 virtual gfxFontGroup *CreateFontGroup(const nsAString& aFamilies,
190 const gfxFontStyle *aStyle,
191 gfxUserFontSet *aUserFontSet) = 0;
195 * Look up a local platform font using the full font face name (needed to support @font-face src local() )
197 virtual gfxFontEntry* LookupLocalFont(const nsAString& aFontName) { return nsnull; }
200 * Activate a platform font (needed to support @font-face src url() )
203 virtual gfxFontEntry* MakePlatformFont(const gfxFontEntry *aProxyEntry, const PRUint8 *aFontData, PRUint32 aLength) { return nsnull; }
206 * Whether to allow downloadable fonts via @font-face rules
208 virtual PRBool DownloadableFontsEnabled();
210 // check whether format is supported on a platform or not (if unclear, returns true)
211 virtual PRBool IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags) { return PR_FALSE; }
213 void GetPrefFonts(const char *aLangGroup, nsString& array, PRBool aAppendUnicode = PR_TRUE);
216 * Iterate over pref fonts given a list of lang groups. For a single lang
217 * group, multiple pref fonts are possible. If error occurs, returns PR_FALSE,
218 * PR_TRUE otherwise. Callback returns PR_FALSE to abort process.
220 typedef PRBool (*PrefFontCallback) (eFontPrefLang aLang, const nsAString& aName,
221 void *aClosure);
222 static PRBool ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangArrayLen,
223 PrefFontCallback aCallback,
224 void *aClosure);
226 // convert a lang group string to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
227 static eFontPrefLang GetFontPrefLangFor(const char* aLang);
229 // convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW")
230 static const char* GetPrefLangName(eFontPrefLang aLang);
232 // returns true if a pref lang is CJK
233 static PRBool IsLangCJK(eFontPrefLang aLang);
235 // helper method to add a pref lang to an array, if not already in array
236 static void AppendPrefLang(eFontPrefLang aPrefLangs[], PRUint32& aLen, eFontPrefLang aAddLang);
239 * Are we going to try color management?
241 static eCMSMode GetCMSMode();
244 * Determines the rendering intent for color management.
246 * If the value in the pref gfx.color_management.rendering_intent is a
247 * valid rendering intent as defined in modules/lcms/include/lcms.h, that
248 * value is returned. Otherwise, -1 is returned and the embedded intent
249 * should be used.
251 * See bug 444014 for details.
253 static int GetRenderingIntent();
256 * Convert a pixel using a cms transform in an endian-aware manner.
258 * Sets 'out' to 'in' if transform is NULL.
260 static void TransformPixel(const gfxRGBA& in, gfxRGBA& out, cmsHTRANSFORM transform);
263 * Return the output device ICC profile.
265 static cmsHPROFILE GetCMSOutputProfile();
268 * Return the sRGB ICC profile.
270 static cmsHPROFILE GetCMSsRGBProfile();
273 * Return sRGB -> output device transform.
275 static cmsHTRANSFORM GetCMSRGBTransform();
278 * Return output -> sRGB device transform.
280 static cmsHTRANSFORM GetCMSInverseRGBTransform();
283 * Return sRGBA -> output device transform.
285 static cmsHTRANSFORM GetCMSRGBATransform();
287 protected:
288 gfxPlatform() { }
289 virtual ~gfxPlatform();
291 private:
292 virtual cmsHPROFILE GetPlatformCMSOutputProfile();
294 nsCOMPtr<nsIObserver> overrideObserver;
297 #endif /* GFX_PLATFORM_H */