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
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.
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
43 #include "nsVoidArray.h"
45 #include "nsIObserver.h"
48 #include "gfxASurface.h"
52 #undef OS2EMX_PLAIN_CHAR
55 typedef void* cmsHPROFILE
;
56 typedef void* cmsHTRANSFORM
;
58 class gfxImageSurface
;
64 class gfxProxyFontEntry
;
67 // pref lang id's for font prefs
68 // !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
71 eFontPrefLang_Western
= 0,
72 eFontPrefLang_CentEuro
= 1,
73 eFontPrefLang_Japanese
= 2,
74 eFontPrefLang_ChineseTW
= 3,
75 eFontPrefLang_ChineseCN
= 4,
76 eFontPrefLang_ChineseHK
= 5,
77 eFontPrefLang_Korean
= 6,
78 eFontPrefLang_Cyrillic
= 7,
79 eFontPrefLang_Baltic
= 8,
80 eFontPrefLang_Greek
= 9,
81 eFontPrefLang_Turkish
= 10,
82 eFontPrefLang_Thai
= 11,
83 eFontPrefLang_Hebrew
= 12,
84 eFontPrefLang_Arabic
= 13,
85 eFontPrefLang_Devanagari
= 14,
86 eFontPrefLang_Tamil
= 15,
87 eFontPrefLang_Armenian
= 16,
88 eFontPrefLang_Bengali
= 17,
89 eFontPrefLang_Canadian
= 18,
90 eFontPrefLang_Ethiopic
= 19,
91 eFontPrefLang_Georgian
= 20,
92 eFontPrefLang_Gujarati
= 21,
93 eFontPrefLang_Gurmukhi
= 22,
94 eFontPrefLang_Khmer
= 23,
95 eFontPrefLang_Malayalam
= 24,
96 eFontPrefLang_Oriya
= 25,
97 eFontPrefLang_Telugu
= 26,
98 eFontPrefLang_Kannada
= 27,
99 eFontPrefLang_Sinhala
= 28,
101 eFontPrefLang_LangCount
= 29, // except Others and UserDefined.
103 eFontPrefLang_Others
= 29, // x-unicode
104 eFontPrefLang_UserDefined
= 30,
106 eFontPrefLang_CJKSet
= 31, // special code for CJK set
107 eFontPrefLang_AllCount
= 32
111 eCMSMode_Off
= 0, // No color management
112 eCMSMode_All
= 1, // Color manage everything
113 eCMSMode_TaggedOnly
= 2, // Color manage tagged Images Only
114 eCMSMode_AllCount
= 3
117 // when searching through pref langs, max number of pref langs
118 const PRUint32 kMaxLenPrefLangList
= 32;
120 class THEBES_API gfxPlatform
{
123 * Return a pointer to the current active platform.
124 * This is a singleton; it contains mostly convenience
125 * functions to obtain platform-specific objects.
127 static gfxPlatform
*GetPlatform();
130 * Start up Thebes. This can fail.
132 static nsresult
Init();
135 * Clean up static objects to shut down thebes.
137 static void Shutdown();
140 * Create an offscreen surface of the given dimensions
143 virtual already_AddRefed
<gfxASurface
> CreateOffscreenSurface(const gfxIntSize
& size
,
144 gfxASurface::gfxImageFormat imageFormat
) = 0;
147 virtual already_AddRefed
<gfxASurface
> OptimizeImage(gfxImageSurface
*aSurface
,
148 gfxASurface::gfxImageFormat format
);
155 * Fill aListOfFonts with the results of querying the list of font names
156 * that correspond to the given language group or generic font family
157 * (or both, or neither).
159 virtual nsresult
GetFontList(const nsACString
& aLangGroup
,
160 const nsACString
& aGenericFamily
,
161 nsStringArray
& aListOfFonts
);
164 * Rebuilds the any cached system font lists
166 virtual nsresult
UpdateFontList();
169 * Font name resolver, this returns actual font name(s) by the callback
170 * function. If the font doesn't exist, the callback function is not called.
171 * If the callback function returns PR_FALSE, the aAborted value is set to
172 * PR_TRUE, otherwise, PR_FALSE.
174 typedef PRBool (*FontResolverCallback
) (const nsAString
& aName
,
176 virtual nsresult
ResolveFontName(const nsAString
& aFontName
,
177 FontResolverCallback aCallback
,
179 PRBool
& aAborted
) = 0;
182 * Resolving a font name to family name. The result MUST be in the result of GetFontList().
183 * If the name doesn't in the system, aFamilyName will be empty string, but not failed.
185 virtual nsresult
GetStandardFamilyName(const nsAString
& aFontName
, nsAString
& aFamilyName
) = 0;
188 * Create the appropriate platform font group
190 virtual gfxFontGroup
*CreateFontGroup(const nsAString
& aFamilies
,
191 const gfxFontStyle
*aStyle
,
192 gfxUserFontSet
*aUserFontSet
) = 0;
196 * Look up a local platform font using the full font face name.
197 * (Needed to support @font-face src local().)
198 * Ownership of the returned gfxFontEntry is passed to the caller,
199 * who must either AddRef() or delete.
201 virtual gfxFontEntry
* LookupLocalFont(const nsAString
& aFontName
) { return nsnull
; }
204 * Activate a platform font. (Needed to support @font-face src url().)
205 * aFontData must persist as long as a reference is held to aLoader.
206 * Ownership of the returned gfxFontEntry is passed to the caller,
207 * who must either AddRef() or delete.
209 virtual gfxFontEntry
* MakePlatformFont(const gfxProxyFontEntry
*aProxyEntry
,
210 nsISupports
*aLoader
,
211 const PRUint8
*aFontData
,
216 * Whether to allow downloadable fonts via @font-face rules
218 virtual PRBool
DownloadableFontsEnabled();
220 // check whether format is supported on a platform or not (if unclear, returns true)
221 virtual PRBool
IsFontFormatSupported(nsIURI
*aFontURI
, PRUint32 aFormatFlags
) { return PR_FALSE
; }
223 void GetPrefFonts(const char *aLangGroup
, nsString
& array
, PRBool aAppendUnicode
= PR_TRUE
);
226 * Iterate over pref fonts given a list of lang groups. For a single lang
227 * group, multiple pref fonts are possible. If error occurs, returns PR_FALSE,
228 * PR_TRUE otherwise. Callback returns PR_FALSE to abort process.
230 typedef PRBool (*PrefFontCallback
) (eFontPrefLang aLang
, const nsAString
& aName
,
232 static PRBool
ForEachPrefFont(eFontPrefLang aLangArray
[], PRUint32 aLangArrayLen
,
233 PrefFontCallback aCallback
,
236 // convert a lang group string to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
237 static eFontPrefLang
GetFontPrefLangFor(const char* aLang
);
239 // convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW")
240 static const char* GetPrefLangName(eFontPrefLang aLang
);
242 // returns true if a pref lang is CJK
243 static PRBool
IsLangCJK(eFontPrefLang aLang
);
245 // helper method to add a pref lang to an array, if not already in array
246 static void AppendPrefLang(eFontPrefLang aPrefLangs
[], PRUint32
& aLen
, eFontPrefLang aAddLang
);
249 * Are we going to try color management?
251 static eCMSMode
GetCMSMode();
254 * Determines the rendering intent for color management.
256 * If the value in the pref gfx.color_management.rendering_intent is a
257 * valid rendering intent as defined in modules/lcms/include/lcms.h, that
258 * value is returned. Otherwise, -1 is returned and the embedded intent
261 * See bug 444014 for details.
263 static int GetRenderingIntent();
266 * Convert a pixel using a cms transform in an endian-aware manner.
268 * Sets 'out' to 'in' if transform is NULL.
270 static void TransformPixel(const gfxRGBA
& in
, gfxRGBA
& out
, cmsHTRANSFORM transform
);
273 * Return the output device ICC profile.
275 static cmsHPROFILE
GetCMSOutputProfile();
278 * Return the sRGB ICC profile.
280 static cmsHPROFILE
GetCMSsRGBProfile();
283 * Return sRGB -> output device transform.
285 static cmsHTRANSFORM
GetCMSRGBTransform();
288 * Return output -> sRGB device transform.
290 static cmsHTRANSFORM
GetCMSInverseRGBTransform();
293 * Return sRGBA -> output device transform.
295 static cmsHTRANSFORM
GetCMSRGBATransform();
299 virtual ~gfxPlatform();
302 virtual cmsHPROFILE
GetPlatformCMSOutputProfile();
304 nsCOMPtr
<nsIObserver
> overrideObserver
;
307 #endif /* GFX_PLATFORM_H */