1 /* vim: set sw=4 sts=4 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
15 * The Original Code is OS/2 code in Thebes.
17 * The Initial Developer of the Original Code is
18 * Peter Weilbacher <mozilla@Weilbacher.org>.
19 * Portions created by the Initial Developer are Copyright (C) 2006-2007
20 * the Initial Developer. All Rights Reserved.
23 * author of code taken from gfxPlatformGtk:
24 * Masayuki Nakano <masayuki@d-toybox.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "gfxOS2Platform.h"
41 #include "gfxOS2Surface.h"
42 #include "gfxImageSurface.h"
43 #include "gfxOS2Fonts.h"
45 #include "gfxFontconfigUtils.h"
46 //#include <fontconfig/fontconfig.h>
48 /**********************************************************************
49 * class gfxOS2Platform
50 **********************************************************************/
51 gfxFontconfigUtils
*gfxOS2Platform::sFontconfigUtils
= nsnull
;
53 gfxOS2Platform::gfxOS2Platform()
56 printf("gfxOS2Platform::gfxOS2Platform()\n");
58 // this seems to be reasonably early in the process and only once,
59 // so it's a good place to initialize OS/2 cairo stuff
62 printf(" cairo_os2_init() was called\n");
64 if (!sFontconfigUtils
) {
65 sFontconfigUtils
= gfxFontconfigUtils::GetFontconfigUtils();
69 gfxOS2Platform::~gfxOS2Platform()
72 printf("gfxOS2Platform::~gfxOS2Platform()\n");
74 gfxFontconfigUtils::Shutdown();
75 sFontconfigUtils
= nsnull
;
77 // clean up OS/2 cairo stuff
80 printf(" cairo_os2_fini() was called\n");
84 already_AddRefed
<gfxASurface
>
85 gfxOS2Platform::CreateOffscreenSurface(const gfxIntSize
& aSize
,
86 gfxASurface::gfxImageFormat aImageFormat
)
89 printf("gfxOS2Platform::CreateOffscreenSurface(%d/%d, %d)\n",
90 aSize
.width
, aSize
.height
, aImageFormat
);
92 gfxASurface
*newSurface
= nsnull
;
94 // we only ever seem to get aImageFormat=0 or ImageFormatARGB32 but
95 // I don't really know if we need to differ between ARGB32 and RGB24 here
96 if (aImageFormat
== gfxASurface::ImageFormatARGB32
||
97 aImageFormat
== gfxASurface::ImageFormatRGB24
)
99 newSurface
= new gfxOS2Surface(aSize
, aImageFormat
);
100 } else if (aImageFormat
== gfxASurface::ImageFormatA8
||
101 aImageFormat
== gfxASurface::ImageFormatA1
) {
102 newSurface
= new gfxImageSurface(aSize
, aImageFormat
);
107 NS_IF_ADDREF(newSurface
);
112 gfxOS2Platform::GetFontList(const nsACString
& aLangGroup
,
113 const nsACString
& aGenericFamily
,
114 nsStringArray
& aListOfFonts
)
117 char *langgroup
= ToNewCString(aLangGroup
),
118 *family
= ToNewCString(aGenericFamily
);
119 printf("gfxOS2Platform::GetFontList(%s, %s, ..)\n",
124 return sFontconfigUtils
->GetFontList(aLangGroup
, aGenericFamily
,
128 nsresult
gfxOS2Platform::UpdateFontList()
131 printf("gfxOS2Platform::UpdateFontList()\n");
133 mCodepointsWithNoFonts
.reset();
135 nsresult rv
= sFontconfigUtils
->UpdateFontList();
137 // initialize ranges of characters for which system-wide font search should be skipped
138 mCodepointsWithNoFonts
.SetRange(0,0x1f); // C0 controls
139 mCodepointsWithNoFonts
.SetRange(0x7f,0x9f); // C1 controls
144 gfxOS2Platform::ResolveFontName(const nsAString
& aFontName
,
145 FontResolverCallback aCallback
,
146 void *aClosure
, PRBool
& aAborted
)
149 char *fontname
= ToNewCString(aFontName
);
150 printf("gfxOS2Platform::ResolveFontName(%s, ...)\n", fontname
);
153 return sFontconfigUtils
->ResolveFontName(aFontName
, aCallback
, aClosure
,
158 gfxOS2Platform::GetStandardFamilyName(const nsAString
& aFontName
, nsAString
& aFamilyName
)
160 return sFontconfigUtils
->GetStandardFamilyName(aFontName
, aFamilyName
);
164 gfxOS2Platform::CreateFontGroup(const nsAString
&aFamilies
,
165 const gfxFontStyle
*aStyle
,
166 gfxUserFontSet
*aUserFontSet
)
168 return new gfxOS2FontGroup(aFamilies
, aStyle
, aUserFontSet
);
171 already_AddRefed
<gfxOS2Font
>
172 gfxOS2Platform::FindFontForChar(PRUint32 aCh
, gfxOS2Font
*aFont
)
175 printf("gfxOS2Platform::FindFontForChar(%d, ...)\n", aCh
);
178 // is codepoint with no matching font? return null immediately
179 if (mCodepointsWithNoFonts
.test(aCh
)) {
183 // the following is not very clever but it's a quick fix to search all fonts
184 // (one should instead cache the charmaps as done on Mac and Win)
186 // just continue to append all fonts known to the system
187 nsStringArray fontList
;
188 nsCAutoString generic
;
189 nsresult rv
= GetFontList(aFont
->GetStyle()->langGroup
, generic
, fontList
);
190 if (NS_SUCCEEDED(rv
)) {
191 // start at 3 to skip over the generic entries
192 for (int i
= 3; i
< fontList
.Count(); i
++) {
194 printf("searching in entry i=%d (%s)\n",
195 i
, NS_LossyConvertUTF16toASCII(*fontList
[i
]).get());
197 nsRefPtr
<gfxOS2Font
> font
=
198 gfxOS2Font::GetOrMakeFont(*fontList
[i
], aFont
->GetStyle());
201 FT_Face face
= cairo_ft_scaled_font_lock_face(font
->CairoScaledFont());
202 if (!face
|| !face
->charmap
) {
204 cairo_ft_scaled_font_unlock_face(font
->CairoScaledFont());
208 FT_UInt gid
= FT_Get_Char_Index(face
, aCh
); // find the glyph id
211 cairo_ft_scaled_font_unlock_face(font
->CairoScaledFont());
212 return font
.forget();
217 // no match found, so add to the set of non-matching codepoints
218 mCodepointsWithNoFonts
.set(aCh
);