2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Foundation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Stuart Parmenter <stuart@mozilla.com>
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
|
|
|
* Masatoshi Kimura <VYV03354@nifty.ne.jp>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
|
|
|
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
|
|
|
|
#include "nsIPref.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2009-01-18 12:14:14 -08:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIWindowsRegKey.h"
|
2008-09-30 20:01:53 -07:00
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "plbase64.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
#include "ft2build.h"
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include "gfxFT2Fonts.h"
|
|
|
|
#include "cairo-ft.h"
|
|
|
|
#else
|
2007-04-02 12:06:16 -07:00
|
|
|
#include "gfxWindowsFonts.h"
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WINCE
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#endif
|
|
|
|
|
2008-09-30 20:01:53 -07:00
|
|
|
#include "gfxUserFontSet.h"
|
2007-04-02 12:06:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <string>
|
|
|
|
|
2007-07-23 15:02:17 -07:00
|
|
|
#include "lcms.h"
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
static FT_Library gPlatformFTLibrary = NULL;
|
|
|
|
#endif
|
2007-05-29 17:07:03 -07:00
|
|
|
|
2008-04-03 19:01:22 -07:00
|
|
|
// font info loader constants
|
|
|
|
static const PRUint32 kDelayBeforeLoadingCmaps = 8 * 1000; // 8secs
|
|
|
|
static const PRUint32 kIntervalBetweenLoadingCmaps = 150; // 150ms
|
|
|
|
static const PRUint32 kNumFontsPerSlice = 10; // read in info 10 fonts at a time
|
|
|
|
|
2008-03-26 14:32:51 -07:00
|
|
|
static __inline void
|
|
|
|
BuildKeyNameFromFontName(nsAString &aName)
|
|
|
|
{
|
|
|
|
if (aName.Length() >= LF_FACESIZE)
|
|
|
|
aName.Truncate(LF_FACESIZE - 1);
|
|
|
|
ToLowerCase(aName);
|
|
|
|
}
|
2008-03-18 17:06:55 -07:00
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
int
|
2007-08-24 12:41:16 -07:00
|
|
|
gfxWindowsPlatform::PrefChangedCallback(const char *aPrefName, void *closure)
|
|
|
|
{
|
2007-08-24 17:00:41 -07:00
|
|
|
// XXX this could be made to only clear out the cache for the prefs that were changed
|
|
|
|
// but it probably isn't that big a deal.
|
2007-08-24 12:41:16 -07:00
|
|
|
gfxWindowsPlatform *plat = static_cast<gfxWindowsPlatform *>(closure);
|
|
|
|
plat->mPrefFonts.Clear();
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-29 17:07:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
gfxWindowsPlatform::gfxWindowsPlatform()
|
2008-04-03 19:01:22 -07:00
|
|
|
: mStartIndex(0), mIncrement(kNumFontsPerSlice), mNumFamilies(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mFonts.Init(200);
|
|
|
|
mFontAliases.Init(20);
|
|
|
|
mFontSubstitutes.Init(50);
|
2007-08-24 12:41:16 -07:00
|
|
|
mPrefFonts.Init(10);
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
FT_Init_FreeType(&gPlatformFTLibrary);
|
|
|
|
#else
|
|
|
|
FontEntry::InitializeFontEmbeddingProcs();
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
UpdateFontList();
|
2007-08-24 12:41:16 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
|
|
|
|
pref->RegisterCallback("font.", PrefChangedCallback, this);
|
|
|
|
pref->RegisterCallback("font.name-list.", PrefChangedCallback, this);
|
2007-08-24 17:00:41 -07:00
|
|
|
pref->RegisterCallback("intl.accept_languages", PrefChangedCallback, this);
|
2007-08-24 12:41:16 -07:00
|
|
|
// don't bother unregistering. We'll get shutdown after the pref service
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxWindowsPlatform::~gfxWindowsPlatform()
|
|
|
|
{
|
2009-01-22 22:24:29 -08:00
|
|
|
// not calling FT_Done_FreeType because cairo may still hold references to
|
|
|
|
// these FT_Faces. See bug 458169.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxWindowsPlatform::CreateOffscreenSurface(const gfxIntSize& size,
|
|
|
|
gfxASurface::gfxImageFormat imageFormat)
|
|
|
|
{
|
2009-01-14 16:19:39 -08:00
|
|
|
#ifndef WINCE
|
2007-03-22 10:30:00 -07:00
|
|
|
gfxASurface *surf = new gfxWindowsSurface(size, imageFormat);
|
2009-01-14 16:19:39 -08:00
|
|
|
#else
|
|
|
|
gfxASurface *surf = new gfxImageSurface(size, imageFormat);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IF_ADDREF(surf);
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CALLBACK
|
|
|
|
gfxWindowsPlatform::FontEnumProc(const ENUMLOGFONTEXW *lpelfe,
|
|
|
|
const NEWTEXTMETRICEXW *nmetrics,
|
|
|
|
DWORD fontType, LPARAM data)
|
|
|
|
{
|
2008-03-18 17:06:55 -07:00
|
|
|
FontTable *ht = reinterpret_cast<FontTable*>(data);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const NEWTEXTMETRICW& metrics = nmetrics->ntmTm;
|
2008-03-26 14:32:51 -07:00
|
|
|
const LOGFONTW& logFont = lpelfe->elfLogFont;
|
2007-06-25 14:51:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Ignore vertical fonts
|
2008-03-26 14:32:51 -07:00
|
|
|
if (logFont.lfFaceName[0] == L'@')
|
2007-03-22 10:30:00 -07:00
|
|
|
return 1;
|
2008-03-26 13:24:37 -07:00
|
|
|
|
2008-03-26 14:32:51 -07:00
|
|
|
nsAutoString name(logFont.lfFaceName);
|
|
|
|
BuildKeyNameFromFontName(name);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 17:06:55 -07:00
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (!ht->Get(name, &ff)) {
|
|
|
|
ff = new FontFamily(nsDependentString(logFont.lfFaceName));
|
|
|
|
ht->Put(name, ff);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-03-26 13:24:37 -07:00
|
|
|
|
2008-03-26 14:32:51 -07:00
|
|
|
// general cmap reading routines moved to gfxFontUtils.cpp
|
2008-03-26 13:24:37 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct FontListData {
|
2009-01-18 12:14:14 -08:00
|
|
|
FontListData(const nsACString& aLangGroup, const nsACString& aGenericFamily, nsTArray<nsString>& aListOfFonts) :
|
2007-03-22 10:30:00 -07:00
|
|
|
mLangGroup(aLangGroup), mGenericFamily(aGenericFamily), mStringArray(aListOfFonts) {}
|
|
|
|
const nsACString& mLangGroup;
|
|
|
|
const nsACString& mGenericFamily;
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString>& mStringArray;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
PLDHashOperator
|
2007-03-22 10:30:00 -07:00
|
|
|
gfxWindowsPlatform::HashEnumFunc(nsStringHashKey::KeyType aKey,
|
2008-03-18 17:06:55 -07:00
|
|
|
nsRefPtr<FontFamily>& aFontFamily,
|
2007-03-22 10:30:00 -07:00
|
|
|
void* userArg)
|
|
|
|
{
|
|
|
|
FontListData *data = (FontListData*)userArg;
|
|
|
|
|
2008-03-18 17:06:55 -07:00
|
|
|
// use the first variation for now. This data should be the same
|
|
|
|
// for all the variations and should probably be moved up to
|
|
|
|
// the Family
|
2008-03-26 14:32:51 -07:00
|
|
|
gfxFontStyle style;
|
|
|
|
style.langGroup = data->mLangGroup;
|
|
|
|
nsRefPtr<FontEntry> aFontEntry = aFontFamily->FindFontEntry(style);
|
2009-03-03 11:14:07 -08:00
|
|
|
NS_ASSERTION(aFontEntry, "couldn't find any font entry in family");
|
|
|
|
if (!aFontEntry)
|
|
|
|
return PL_DHASH_NEXT;
|
2008-03-18 17:06:55 -07:00
|
|
|
|
2009-02-17 23:33:39 -08:00
|
|
|
|
|
|
|
#ifndef MOZ_FT2_FONTS
|
2007-06-25 14:51:15 -07:00
|
|
|
/* skip symbol fonts */
|
|
|
|
if (aFontEntry->mSymbolFont)
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aFontEntry->SupportsLangGroup(data->mLangGroup) &&
|
|
|
|
aFontEntry->MatchesGenericFamily(data->mGenericFamily))
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2009-03-18 09:07:33 -07:00
|
|
|
data->mStringArray.AppendElement(aFontFamily->Name());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxWindowsPlatform::GetFontList(const nsACString& aLangGroup,
|
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
FontListData data(aLangGroup, aGenericFamily, aListOfFonts);
|
|
|
|
|
|
|
|
mFonts.Enumerate(gfxWindowsPlatform::HashEnumFunc, &data);
|
|
|
|
|
|
|
|
aListOfFonts.Sort();
|
|
|
|
aListOfFonts.Compact();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RemoveCharsetFromFontSubstitute(nsAString &aName)
|
|
|
|
{
|
|
|
|
PRInt32 comma = aName.FindChar(PRUnichar(','));
|
|
|
|
if (comma >= 0)
|
|
|
|
aName.Truncate(comma);
|
|
|
|
}
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
void gfxWindowsPlatform::AppendFacesFromFontFile(const PRUnichar *aFileName) {
|
|
|
|
char fileName[MAX_PATH];
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, aFileName, -1, fileName, MAX_PATH, NULL, NULL);
|
|
|
|
FT_Face dummy;
|
|
|
|
if (FT_Err_Ok == FT_New_Face(GetFTLibrary(), fileName, -1, &dummy)) {
|
|
|
|
for (FT_Long i = 0; i < dummy->num_faces; i++) {
|
|
|
|
FT_Face face;
|
|
|
|
if (FT_Err_Ok != FT_New_Face(GetFTLibrary(), fileName,
|
|
|
|
i, &face))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
FontEntry* fe = FontEntry::CreateFontEntryFromFace(face);
|
|
|
|
if (fe) {
|
|
|
|
NS_ConvertUTF8toUTF16 name(face->family_name);
|
|
|
|
BuildKeyNameFromFontName(name);
|
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (!mFonts.Get(name, &ff)) {
|
|
|
|
ff = new FontFamily(name);
|
|
|
|
mFonts.Put(name, ff);
|
|
|
|
}
|
|
|
|
ff->mFaces.AppendElement(fe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FT_Done_Face(dummy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxWindowsPlatform::FindFonts()
|
|
|
|
{
|
|
|
|
nsTArray<nsString> searchPaths(2);
|
|
|
|
nsTArray<nsString> fontPatterns(4);
|
|
|
|
fontPatterns.AppendElement(NS_LITERAL_STRING("\\*.TTF"));
|
|
|
|
fontPatterns.AppendElement(NS_LITERAL_STRING("\\*.ttf"));
|
|
|
|
fontPatterns.AppendElement(NS_LITERAL_STRING("\\*.OTF"));
|
|
|
|
fontPatterns.AppendElement(NS_LITERAL_STRING("\\*.otf"));
|
|
|
|
wchar_t pathBuf[256];
|
|
|
|
SHGetSpecialFolderPathW(0, pathBuf, CSIDL_WINDOWS, 0);
|
|
|
|
searchPaths.AppendElement(pathBuf);
|
|
|
|
SHGetSpecialFolderPathW(0, pathBuf, CSIDL_FONTS, 0);
|
|
|
|
searchPaths.AppendElement(pathBuf);
|
|
|
|
WIN32_FIND_DATAW results;
|
|
|
|
for (PRUint32 i = 0; i < searchPaths.Length(); i++) {
|
|
|
|
const nsString& path(searchPaths[i]);
|
|
|
|
for (PRUint32 j = 0; j < fontPatterns.Length(); j++) {
|
|
|
|
nsAutoString pattern(path);
|
|
|
|
pattern.Append(fontPatterns[j]);
|
|
|
|
HANDLE handle = FindFirstFileW(pattern.get(), &results);
|
|
|
|
PRBool moreFiles = handle != INVALID_HANDLE_VALUE;
|
|
|
|
while (moreFiles) {
|
|
|
|
nsAutoString filePath(path);
|
|
|
|
filePath.AppendLiteral("\\");
|
|
|
|
filePath.Append(results.cFileName);
|
|
|
|
AppendFacesFromFontFile(static_cast<const PRUnichar*>(filePath.get()));
|
|
|
|
moreFiles = FindNextFile(handle, &results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
gfxWindowsPlatform::UpdateFontList()
|
|
|
|
{
|
2008-03-21 14:22:29 -07:00
|
|
|
gfxFontCache *fc = gfxFontCache::GetCache();
|
|
|
|
if (fc)
|
|
|
|
fc->AgeAllGenerations();
|
2007-03-22 10:30:00 -07:00
|
|
|
mFonts.Clear();
|
|
|
|
mFontAliases.Clear();
|
|
|
|
mNonExistingFonts.Clear();
|
|
|
|
mFontSubstitutes.Clear();
|
2007-08-24 12:41:16 -07:00
|
|
|
mPrefFonts.Clear();
|
2008-03-03 18:34:05 -08:00
|
|
|
mCodepointsWithNoFonts.reset();
|
2008-04-03 19:01:22 -07:00
|
|
|
CancelLoader();
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
FindFonts();
|
|
|
|
#else
|
2007-03-22 10:30:00 -07:00
|
|
|
LOGFONTW logFont;
|
|
|
|
logFont.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
logFont.lfFaceName[0] = 0;
|
|
|
|
logFont.lfPitchAndFamily = 0;
|
|
|
|
|
|
|
|
// Use the screen DC here.. should we use something else for printing?
|
|
|
|
HDC dc = ::GetDC(nsnull);
|
2008-03-18 17:06:55 -07:00
|
|
|
EnumFontFamiliesExW(dc, &logFont, (FONTENUMPROCW)gfxWindowsPlatform::FontEnumProc, (LPARAM)&mFonts, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
::ReleaseDC(nsnull, dc);
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2008-04-03 19:01:22 -07:00
|
|
|
// initialize the cmap loading process after font list has been initialized
|
|
|
|
StartLoader(kDelayBeforeLoadingCmaps, kIntervalBetweenLoadingCmaps);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Create the list of FontSubstitutes
|
2007-05-29 17:07:03 -07:00
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey = do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!regKey)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-05-29 17:07:03 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(kFontSubstitutesKey, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-29 17:07:03 -07:00
|
|
|
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
|
|
|
|
kFontSubstitutesKey, nsIWindowsRegKey::ACCESS_READ);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
rv = regKey->GetValueCount(&count);
|
|
|
|
if (NS_FAILED(rv) || count == 0)
|
|
|
|
return rv;
|
|
|
|
for (PRUint32 i = 0; i < count; i++) {
|
|
|
|
nsAutoString substituteName;
|
|
|
|
rv = regKey->GetValueName(i, substituteName);
|
|
|
|
if (NS_FAILED(rv) || substituteName.IsEmpty() ||
|
|
|
|
substituteName.CharAt(1) == PRUnichar('@'))
|
|
|
|
continue;
|
|
|
|
PRUint32 valueType;
|
|
|
|
rv = regKey->GetValueType(substituteName, &valueType);
|
|
|
|
if (NS_FAILED(rv) || valueType != nsIWindowsRegKey::TYPE_STRING)
|
|
|
|
continue;
|
|
|
|
nsAutoString actualFontName;
|
|
|
|
rv = regKey->ReadStringValue(substituteName, actualFontName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
RemoveCharsetFromFontSubstitute(substituteName);
|
|
|
|
BuildKeyNameFromFontName(substituteName);
|
|
|
|
RemoveCharsetFromFontSubstitute(actualFontName);
|
|
|
|
BuildKeyNameFromFontName(actualFontName);
|
2008-03-18 17:06:55 -07:00
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (!actualFontName.IsEmpty() && mFonts.Get(actualFontName, &ff))
|
|
|
|
mFontSubstitutes.Put(substituteName, ff);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2009-01-18 12:14:14 -08:00
|
|
|
mNonExistingFonts.AppendElement(substituteName);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-03 18:34:05 -08:00
|
|
|
// initialize ranges of characters for which system-wide font search should be skipped
|
|
|
|
mCodepointsWithNoFonts.SetRange(0,0x1f); // C0 controls
|
|
|
|
mCodepointsWithNoFonts.SetRange(0x7f,0x9f); // C1 controls
|
|
|
|
|
2008-03-12 19:36:58 -07:00
|
|
|
InitBadUnderlineList();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-03 19:01:22 -07:00
|
|
|
struct FontFamilyListData {
|
|
|
|
FontFamilyListData(nsTArray<nsRefPtr<FontFamily> >& aFamilyArray)
|
|
|
|
: mFamilyArray(aFamilyArray)
|
|
|
|
{}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator AppendFamily(nsStringHashKey::KeyType aKey,
|
|
|
|
nsRefPtr<FontFamily>& aFamilyEntry,
|
|
|
|
void *aUserArg)
|
2008-04-03 19:01:22 -07:00
|
|
|
{
|
|
|
|
FontFamilyListData *data = (FontFamilyListData*)aUserArg;
|
|
|
|
data->mFamilyArray.AppendElement(aFamilyEntry);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<FontFamily> >& mFamilyArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxWindowsPlatform::GetFontFamilyList(nsTArray<nsRefPtr<FontFamily> >& aFamilyArray)
|
|
|
|
{
|
|
|
|
FontFamilyListData data(aFamilyArray);
|
|
|
|
mFonts.Enumerate(FontFamilyListData::AppendFamily, &data);
|
|
|
|
}
|
|
|
|
|
2008-03-12 19:36:58 -07:00
|
|
|
static PRBool SimpleResolverCallback(const nsAString& aName, void* aClosure)
|
|
|
|
{
|
2008-03-26 14:32:51 -07:00
|
|
|
nsString *result = static_cast<nsString*>(aClosure);
|
2008-03-12 19:36:58 -07:00
|
|
|
result->Assign(aName);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxWindowsPlatform::InitBadUnderlineList()
|
|
|
|
{
|
2009-01-22 22:24:29 -08:00
|
|
|
// Only windows fonts have mIsBadUnderlineFontFamily flag
|
|
|
|
#ifndef MOZ_FT2_FONTS
|
2008-04-17 21:32:18 -07:00
|
|
|
nsAutoTArray<nsString, 10> blacklist;
|
2008-03-12 19:36:58 -07:00
|
|
|
gfxFontUtils::GetPrefsFontList("font.blacklist.underline_offset", blacklist);
|
|
|
|
PRUint32 numFonts = blacklist.Length();
|
|
|
|
for (PRUint32 i = 0; i < numFonts; i++) {
|
|
|
|
PRBool aborted;
|
|
|
|
nsAutoString resolved;
|
|
|
|
ResolveFontName(blacklist[i], SimpleResolverCallback, &resolved, aborted);
|
|
|
|
if (resolved.IsEmpty())
|
|
|
|
continue;
|
2008-03-18 17:06:55 -07:00
|
|
|
FontFamily *ff = FindFontFamily(resolved);
|
|
|
|
if (!ff)
|
2008-03-12 19:36:58 -07:00
|
|
|
continue;
|
2008-09-30 20:01:53 -07:00
|
|
|
ff->mIsBadUnderlineFontFamily = 1;
|
2008-03-12 19:36:58 -07:00
|
|
|
}
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2008-03-12 19:36:58 -07:00
|
|
|
}
|
|
|
|
|
2008-03-13 03:32:50 -07:00
|
|
|
nsresult
|
|
|
|
gfxWindowsPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
aFamilyName.Truncate();
|
|
|
|
PRBool aborted;
|
|
|
|
return ResolveFontName(aFontName, SimpleResolverCallback, &aFamilyName, aborted);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct ResolveData {
|
|
|
|
ResolveData(gfxPlatform::FontResolverCallback aCallback,
|
|
|
|
gfxWindowsPlatform *aCaller, const nsAString *aFontName,
|
|
|
|
void *aClosure) :
|
|
|
|
mFoundCount(0), mCallback(aCallback), mCaller(aCaller),
|
|
|
|
mFontName(aFontName), mClosure(aClosure) {}
|
|
|
|
PRUint32 mFoundCount;
|
|
|
|
gfxPlatform::FontResolverCallback mCallback;
|
|
|
|
gfxWindowsPlatform *mCaller;
|
|
|
|
const nsAString *mFontName;
|
|
|
|
void *mClosure;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxWindowsPlatform::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
|
|
|
void *aClosure,
|
|
|
|
PRBool& aAborted)
|
|
|
|
{
|
|
|
|
if (aFontName.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsAutoString keyName(aFontName);
|
|
|
|
BuildKeyNameFromFontName(keyName);
|
|
|
|
|
2008-03-18 17:06:55 -07:00
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (mFonts.Get(keyName, &ff) ||
|
|
|
|
mFontSubstitutes.Get(keyName, &ff) ||
|
|
|
|
mFontAliases.Get(keyName, &ff)) {
|
2009-03-18 09:07:33 -07:00
|
|
|
aAborted = !(*aCallback)(ff->Name(), aClosure);
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX If the font has font link, we should add the linked font.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-18 12:14:14 -08:00
|
|
|
if (mNonExistingFonts.Contains(keyName)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aAborted = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGFONTW logFont;
|
|
|
|
logFont.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
logFont.lfPitchAndFamily = 0;
|
|
|
|
PRInt32 len = aFontName.Length();
|
|
|
|
if (len >= LF_FACESIZE)
|
|
|
|
len = LF_FACESIZE - 1;
|
|
|
|
memcpy(logFont.lfFaceName,
|
|
|
|
nsPromiseFlatString(aFontName).get(), len * sizeof(PRUnichar));
|
|
|
|
logFont.lfFaceName[len] = 0;
|
|
|
|
|
|
|
|
HDC dc = ::GetDC(nsnull);
|
|
|
|
ResolveData data(aCallback, this, &keyName, aClosure);
|
2008-03-18 17:06:55 -07:00
|
|
|
aAborted = !EnumFontFamiliesExW(dc, &logFont,
|
|
|
|
(FONTENUMPROCW)gfxWindowsPlatform::FontResolveProc,
|
|
|
|
(LPARAM)&data, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (data.mFoundCount == 0)
|
2009-01-18 12:14:14 -08:00
|
|
|
mNonExistingFonts.AppendElement(keyName);
|
2007-03-22 10:30:00 -07:00
|
|
|
::ReleaseDC(nsnull, dc);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CALLBACK
|
|
|
|
gfxWindowsPlatform::FontResolveProc(const ENUMLOGFONTEXW *lpelfe,
|
|
|
|
const NEWTEXTMETRICEXW *nmetrics,
|
|
|
|
DWORD fontType, LPARAM data)
|
|
|
|
{
|
|
|
|
const LOGFONTW& logFont = lpelfe->elfLogFont;
|
|
|
|
// Ignore vertical fonts
|
|
|
|
if (logFont.lfFaceName[0] == L'@' || logFont.lfFaceName[0] == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
ResolveData *rData = reinterpret_cast<ResolveData*>(data);
|
|
|
|
|
|
|
|
nsAutoString name(logFont.lfFaceName);
|
|
|
|
|
|
|
|
// Save the alias name to cache
|
2008-03-18 17:06:55 -07:00
|
|
|
nsRefPtr<FontFamily> ff;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString keyName(name);
|
|
|
|
BuildKeyNameFromFontName(keyName);
|
2008-03-18 17:06:55 -07:00
|
|
|
if (!rData->mCaller->mFonts.Get(keyName, &ff)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// This case only occurs on failing to build
|
|
|
|
// the list of font substitue. In this case, the user should
|
|
|
|
// reboot the Windows. Probably, we don't have the good way for
|
|
|
|
// resolving in this time.
|
|
|
|
NS_WARNING("Cannot find actual font");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rData->mFoundCount++;
|
2008-03-18 17:06:55 -07:00
|
|
|
rData->mCaller->mFontAliases.Put(*(rData->mFontName), ff);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return (rData->mCallback)(name, rData->mClosure);
|
|
|
|
|
|
|
|
// XXX If the font has font link, we should add the linked font.
|
|
|
|
}
|
|
|
|
|
|
|
|
struct FontSearch {
|
2009-01-22 22:24:29 -08:00
|
|
|
FontSearch(PRUint32 aCh, gfxFont *aFont) :
|
2008-03-22 18:13:10 -07:00
|
|
|
ch(aCh), fontToMatch(aFont), matchRank(-1) {
|
2007-05-29 08:09:23 -07:00
|
|
|
}
|
2008-03-03 18:34:05 -08:00
|
|
|
PRUint32 ch;
|
2009-01-22 22:24:29 -08:00
|
|
|
nsRefPtr<gfxFont> fontToMatch;
|
2007-05-29 17:07:03 -07:00
|
|
|
PRInt32 matchRank;
|
|
|
|
nsRefPtr<FontEntry> bestMatch;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
PLDHashOperator
|
2008-03-03 18:34:05 -08:00
|
|
|
gfxWindowsPlatform::FindFontForCharProc(nsStringHashKey::KeyType aKey,
|
2008-03-18 17:06:55 -07:00
|
|
|
nsRefPtr<FontFamily>& aFontFamily,
|
|
|
|
void* userArg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
FontSearch *data = (FontSearch*)userArg;
|
2007-05-29 08:09:23 -07:00
|
|
|
|
2008-03-19 17:41:19 -07:00
|
|
|
const PRUint32 ch = data->ch;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-26 14:32:51 -07:00
|
|
|
nsRefPtr<FontEntry> fe = aFontFamily->FindFontEntry(*data->fontToMatch->GetStyle());
|
2009-03-03 11:14:07 -08:00
|
|
|
NS_ASSERTION(fe, "couldn't find any font entry in family");
|
|
|
|
if (!fe)
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
PRInt32 rank = 0;
|
2007-05-29 08:09:23 -07:00
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifndef MOZ_FT2_FONTS
|
2008-03-19 17:41:19 -07:00
|
|
|
// skip over non-unicode and bitmap fonts and fonts that don't have
|
|
|
|
// the code point we're looking for
|
|
|
|
if (fe->IsCrappyFont() || !fe->mCharacterMap.test(ch))
|
|
|
|
return PL_DHASH_NEXT;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-19 17:41:19 -07:00
|
|
|
// fonts that claim to support the range are more
|
|
|
|
// likely to be "better fonts" than ones that don't... (in theory)
|
|
|
|
if (fe->SupportsRange(gfxFontUtils::CharRangeBit(ch)))
|
|
|
|
rank += 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-19 17:41:19 -07:00
|
|
|
if (fe->SupportsLangGroup(data->fontToMatch->GetStyle()->langGroup))
|
|
|
|
rank += 2;
|
2008-03-18 17:06:55 -07:00
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
FontEntry* mfe = static_cast<FontEntry*>(data->fontToMatch->GetFontEntry());
|
|
|
|
|
|
|
|
if (fe->mWindowsFamily == mfe->mWindowsFamily)
|
2008-03-19 17:41:19 -07:00
|
|
|
rank += 3;
|
2009-01-22 22:24:29 -08:00
|
|
|
if (fe->mWindowsPitch == mfe->mWindowsPitch)
|
2008-03-19 17:41:19 -07:00
|
|
|
rank += 3;
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2008-03-19 17:41:19 -07:00
|
|
|
/* italic */
|
2008-03-26 14:32:51 -07:00
|
|
|
const PRBool italic = (data->fontToMatch->GetStyle()->style != FONT_STYLE_NORMAL);
|
2008-03-19 17:41:19 -07:00
|
|
|
if (fe->mItalic != italic)
|
|
|
|
rank += 3;
|
|
|
|
|
|
|
|
/* weight */
|
|
|
|
PRInt8 baseWeight, weightDistance;
|
|
|
|
data->fontToMatch->GetStyle()->ComputeWeightAndOffset(&baseWeight, &weightDistance);
|
|
|
|
if (fe->mWeight == (baseWeight * 100) + (weightDistance * 100))
|
|
|
|
rank += 2;
|
|
|
|
else if (fe->mWeight == data->fontToMatch->GetFontEntry()->mWeight)
|
|
|
|
rank += 1;
|
|
|
|
|
|
|
|
if (rank > data->matchRank ||
|
2008-08-05 21:34:06 -07:00
|
|
|
(rank == data->matchRank && Compare(fe->Name(), data->bestMatch->Name()) > 0)) {
|
2008-03-19 17:41:19 -07:00
|
|
|
data->bestMatch = fe;
|
|
|
|
data->matchRank = rank;
|
2007-05-29 08:09:23 -07:00
|
|
|
}
|
2007-05-29 17:07:03 -07:00
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
2007-05-29 08:09:23 -07:00
|
|
|
}
|
2007-05-29 03:24:15 -07:00
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
already_AddRefed<gfxFont>
|
|
|
|
gfxWindowsPlatform::FindFontForChar(PRUint32 aCh, gfxFont *aFont)
|
2007-05-29 08:09:23 -07:00
|
|
|
{
|
2008-03-03 18:34:05 -08:00
|
|
|
// is codepoint with no matching font? return null immediately
|
|
|
|
if (mCodepointsWithNoFonts.test(aCh)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontSearch data(aCh, aFont);
|
2007-05-29 17:07:03 -07:00
|
|
|
|
|
|
|
// find fonts that support the character
|
2008-03-03 18:34:05 -08:00
|
|
|
mFonts.Enumerate(gfxWindowsPlatform::FindFontForCharProc, &data);
|
2007-05-29 17:07:03 -07:00
|
|
|
|
2008-04-29 20:37:30 -07:00
|
|
|
if (data.bestMatch) {
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
nsRefPtr<gfxFT2Font> font =
|
|
|
|
gfxFT2Font::GetOrMakeFont(data.bestMatch->mName,
|
|
|
|
aFont->GetStyle());
|
|
|
|
gfxFont* ret = font.forget().get();
|
|
|
|
return already_AddRefed<gfxFont>(ret);
|
|
|
|
#else
|
2008-04-29 20:37:30 -07:00
|
|
|
nsRefPtr<gfxWindowsFont> font =
|
|
|
|
gfxWindowsFont::GetOrMakeFont(data.bestMatch, aFont->GetStyle());
|
2009-01-22 22:24:29 -08:00
|
|
|
if (font->IsValid()) {
|
|
|
|
gfxFont* ret = font.forget().get();
|
|
|
|
return already_AddRefed<gfxFont>(ret);
|
|
|
|
}
|
|
|
|
#endif
|
2008-04-29 20:37:30 -07:00
|
|
|
return nsnull;
|
2008-03-03 18:34:05 -08:00
|
|
|
}
|
2008-04-29 20:37:30 -07:00
|
|
|
// no match? add to set of non-matching codepoints
|
|
|
|
mCodepointsWithNoFonts.set(aCh);
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-02 12:06:16 -07:00
|
|
|
|
|
|
|
gfxFontGroup *
|
|
|
|
gfxWindowsPlatform::CreateFontGroup(const nsAString &aFamilies,
|
2008-09-30 20:01:53 -07:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet *aUserFontSet)
|
|
|
|
{
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
return new gfxFT2FontGroup(aFamilies, aStyle);
|
|
|
|
#else
|
2008-09-30 20:01:53 -07:00
|
|
|
return new gfxWindowsFontGroup(aFamilies, aStyle, aUserFontSet);
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct FullFontNameSearch {
|
|
|
|
FullFontNameSearch(const nsAString& aFullName)
|
|
|
|
: mFound(PR_FALSE), mFullName(aFullName), mDC(nsnull), mFontEntry(nsnull)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
PRPackedBool mFound;
|
|
|
|
nsString mFullName;
|
|
|
|
nsString mFamilyName;
|
|
|
|
HDC mDC;
|
|
|
|
gfxFontEntry *mFontEntry;
|
|
|
|
};
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifndef MOZ_FT2_FONTS
|
2008-09-30 20:01:53 -07:00
|
|
|
// callback called for each face within a single family
|
|
|
|
// match against elfFullName
|
|
|
|
|
|
|
|
static int CALLBACK
|
|
|
|
FindFullNameForFace(const ENUMLOGFONTEXW *lpelfe,
|
|
|
|
const NEWTEXTMETRICEXW *nmetrics,
|
|
|
|
DWORD fontType, LPARAM userArg)
|
|
|
|
{
|
|
|
|
FullFontNameSearch *data = reinterpret_cast<FullFontNameSearch*>(userArg);
|
|
|
|
|
|
|
|
// does the full name match?
|
|
|
|
if (!data->mFullName.Equals(nsDependentString(lpelfe->elfFullName)))
|
|
|
|
return 1; // continue
|
|
|
|
|
|
|
|
// found match, create a new font entry
|
|
|
|
data->mFound = PR_TRUE;
|
|
|
|
|
|
|
|
const NEWTEXTMETRICW& metrics = nmetrics->ntmTm;
|
|
|
|
LOGFONTW logFont = lpelfe->elfLogFont;
|
|
|
|
|
|
|
|
// Some fonts claim to support things > 900, but we don't so clamp the sizes
|
|
|
|
logFont.lfWeight = PR_MAX(PR_MIN(logFont.lfWeight, 900), 100);
|
|
|
|
|
|
|
|
gfxWindowsFontType feType = FontEntry::DetermineFontType(metrics, fontType);
|
|
|
|
|
|
|
|
data->mFontEntry = FontEntry::CreateFontEntry(data->mFamilyName, feType, (logFont.lfItalic == 0xFF), (PRUint16) (logFont.lfWeight), nsnull, data->mDC, &logFont);
|
2009-01-22 22:24:29 -08:00
|
|
|
|
2008-09-30 20:01:53 -07:00
|
|
|
return 0; // stop iteration
|
|
|
|
}
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2008-09-30 20:01:53 -07:00
|
|
|
|
|
|
|
// callback called for each family name, based on the assumption that the
|
|
|
|
// first part of the full name is the family name
|
|
|
|
|
2008-10-20 23:50:05 -07:00
|
|
|
static PLDHashOperator
|
2008-09-30 20:01:53 -07:00
|
|
|
FindFullName(nsStringHashKey::KeyType aKey,
|
|
|
|
nsRefPtr<FontFamily>& aFontFamily,
|
|
|
|
void* userArg)
|
|
|
|
{
|
|
|
|
FullFontNameSearch *data = reinterpret_cast<FullFontNameSearch*>(userArg);
|
|
|
|
|
|
|
|
// does the family name match up to the length of the family name?
|
|
|
|
const nsString& family = aFontFamily->Name();
|
|
|
|
|
|
|
|
nsString fullNameFamily;
|
|
|
|
data->mFullName.Left(fullNameFamily, family.Length());
|
|
|
|
|
|
|
|
// if so, iterate over faces in this family to see if there is a match
|
|
|
|
if (family.Equals(fullNameFamily)) {
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
int len = aFontFamily->mFaces.Length();
|
|
|
|
int index = 0;
|
|
|
|
for (; index < len &&
|
|
|
|
!aFontFamily->mFaces[index]->Name().Equals(data->mFullName); index++);
|
|
|
|
if (index < len) {
|
|
|
|
data->mFound = PR_TRUE;
|
|
|
|
data->mFontEntry = aFontFamily->mFaces[index];
|
|
|
|
}
|
|
|
|
#else
|
2008-09-30 20:01:53 -07:00
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
if (!data->mDC) {
|
|
|
|
data->mDC= GetDC(nsnull);
|
|
|
|
SetGraphicsMode(data->mDC, GM_ADVANCED);
|
|
|
|
}
|
|
|
|
hdc = data->mDC;
|
|
|
|
|
|
|
|
LOGFONTW logFont;
|
|
|
|
memset(&logFont, 0, sizeof(LOGFONTW));
|
|
|
|
logFont.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
logFont.lfPitchAndFamily = 0;
|
|
|
|
PRUint32 l = PR_MIN(family.Length(), LF_FACESIZE - 1);
|
|
|
|
memcpy(logFont.lfFaceName,
|
|
|
|
nsPromiseFlatString(family).get(),
|
|
|
|
l * sizeof(PRUnichar));
|
|
|
|
logFont.lfFaceName[l] = 0;
|
|
|
|
data->mFamilyName.Assign(family);
|
|
|
|
|
|
|
|
EnumFontFamiliesExW(hdc, &logFont, (FONTENUMPROCW)FindFullNameForFace, (LPARAM)data, 0);
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data->mFound)
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2009-01-02 19:21:49 -08:00
|
|
|
gfxWindowsPlatform::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName)
|
2008-09-30 20:01:53 -07:00
|
|
|
{
|
|
|
|
// walk over list of names
|
|
|
|
FullFontNameSearch data(aFontName);
|
|
|
|
|
|
|
|
// find fonts that support the character
|
|
|
|
mFonts.Enumerate(FindFullName, &data);
|
|
|
|
|
|
|
|
if (data.mDC)
|
|
|
|
ReleaseDC(nsnull, data.mDC);
|
|
|
|
|
|
|
|
return data.mFontEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2008-12-05 15:19:27 -08:00
|
|
|
gfxWindowsPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
nsISupports *aLoader,
|
2008-10-29 11:09:50 -07:00
|
|
|
const PRUint8 *aFontData, PRUint32 aLength)
|
2008-09-30 20:01:53 -07:00
|
|
|
{
|
2009-04-01 22:48:23 -07:00
|
|
|
return FontEntry::CreateFontEntry(*aProxyEntry, aLoader,
|
|
|
|
aFontData, aLength);
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
gfxWindowsPlatform::IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags)
|
|
|
|
{
|
2009-01-12 21:16:58 -08:00
|
|
|
// check for strange format flags
|
|
|
|
NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
|
|
|
|
"strange font format hint set");
|
|
|
|
|
|
|
|
// accept supported formats
|
|
|
|
if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) {
|
|
|
|
return PR_TRUE;
|
2008-09-30 20:01:53 -07:00
|
|
|
}
|
|
|
|
|
2009-01-12 21:16:58 -08:00
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2008-09-30 20:01:53 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-12 21:16:58 -08:00
|
|
|
// no format hint set, need to look at data
|
2008-09-30 20:01:53 -07:00
|
|
|
return PR_TRUE;
|
2007-04-02 12:06:16 -07:00
|
|
|
}
|
2007-05-29 17:07:03 -07:00
|
|
|
|
2008-03-18 17:06:55 -07:00
|
|
|
FontFamily *
|
|
|
|
gfxWindowsPlatform::FindFontFamily(const nsAString& aName)
|
2007-05-29 17:07:03 -07:00
|
|
|
{
|
2008-03-26 14:32:51 -07:00
|
|
|
nsAutoString name(aName);
|
|
|
|
BuildKeyNameFromFontName(name);
|
2007-05-29 17:07:03 -07:00
|
|
|
|
2008-03-18 17:06:55 -07:00
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (!mFonts.Get(name, &ff) &&
|
|
|
|
!mFontSubstitutes.Get(name, &ff) &&
|
|
|
|
!mFontAliases.Get(name, &ff)) {
|
2007-05-29 17:07:03 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
2008-03-18 17:06:55 -07:00
|
|
|
return ff.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
FontEntry *
|
2008-03-26 14:32:51 -07:00
|
|
|
gfxWindowsPlatform::FindFontEntry(const nsAString& aName, const gfxFontStyle& aFontStyle)
|
2008-03-18 17:06:55 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<FontFamily> ff = FindFontFamily(aName);
|
|
|
|
if (!ff)
|
|
|
|
return nsnull;
|
|
|
|
|
2008-03-26 14:32:51 -07:00
|
|
|
return ff->FindFontEntry(aFontStyle);
|
2007-05-29 17:07:03 -07:00
|
|
|
}
|
2007-07-23 15:02:17 -07:00
|
|
|
|
|
|
|
cmsHPROFILE
|
|
|
|
gfxWindowsPlatform::GetPlatformCMSOutputProfile()
|
|
|
|
{
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifndef MOZ_FT2_FONTS
|
2007-07-23 15:02:17 -07:00
|
|
|
WCHAR str[1024+1];
|
|
|
|
DWORD size = 1024;
|
|
|
|
|
|
|
|
HDC dc = GetDC(nsnull);
|
|
|
|
GetICMProfileW(dc, &size, (LPWSTR)&str);
|
|
|
|
ReleaseDC(nsnull, dc);
|
|
|
|
|
|
|
|
cmsHPROFILE profile =
|
|
|
|
cmsOpenProfileFromFile(NS_ConvertUTF16toUTF8(str).get(), "r");
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
if (profile)
|
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s successfully\n",
|
|
|
|
NS_ConvertUTF16toUTF8(str).get());
|
|
|
|
#endif
|
|
|
|
return profile;
|
2008-12-03 05:42:03 -08:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
2007-07-23 15:02:17 -07:00
|
|
|
}
|
2007-08-24 12:41:16 -07:00
|
|
|
|
|
|
|
PRBool
|
2008-03-18 17:06:55 -07:00
|
|
|
gfxWindowsPlatform::GetPrefFontEntries(const nsCString& aKey, nsTArray<nsRefPtr<FontEntry> > *array)
|
2007-08-24 12:41:16 -07:00
|
|
|
{
|
2008-03-18 17:06:55 -07:00
|
|
|
return mPrefFonts.Get(aKey, array);
|
2007-08-24 12:41:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-18 17:06:55 -07:00
|
|
|
gfxWindowsPlatform::SetPrefFontEntries(const nsCString& aKey, nsTArray<nsRefPtr<FontEntry> >& array)
|
2007-08-24 12:41:16 -07:00
|
|
|
{
|
2008-03-18 17:06:55 -07:00
|
|
|
mPrefFonts.Put(aKey, array);
|
2007-08-24 12:41:16 -07:00
|
|
|
}
|
2008-04-03 19:01:22 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxWindowsPlatform::InitLoader()
|
|
|
|
{
|
|
|
|
GetFontFamilyList(mFontFamilies);
|
|
|
|
mStartIndex = 0;
|
|
|
|
mNumFamilies = mFontFamilies.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
gfxWindowsPlatform::RunLoader()
|
|
|
|
{
|
|
|
|
PRUint32 i, endIndex = ( mStartIndex + mIncrement < mNumFamilies ? mStartIndex + mIncrement : mNumFamilies );
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifndef MOZ_FT2_FONTS
|
2008-04-03 19:01:22 -07:00
|
|
|
// for each font family, load in various font info
|
|
|
|
for (i = mStartIndex; i < endIndex; i++) {
|
|
|
|
// load the cmaps for all variations
|
|
|
|
mFontFamilies[i]->FindStyleVariations();
|
|
|
|
}
|
2009-01-22 22:24:29 -08:00
|
|
|
#endif
|
2008-04-03 19:01:22 -07:00
|
|
|
mStartIndex += mIncrement;
|
|
|
|
if (mStartIndex < mNumFamilies)
|
|
|
|
return PR_FALSE;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxWindowsPlatform::FinishLoader()
|
|
|
|
{
|
|
|
|
mFontFamilies.Clear();
|
|
|
|
mNumFamilies = 0;
|
|
|
|
}
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
#ifdef MOZ_FT2_FONTS
|
|
|
|
FT_Library
|
|
|
|
gfxWindowsPlatform::GetFTLibrary()
|
|
|
|
{
|
|
|
|
return gPlatformFTLibrary;
|
|
|
|
}
|
|
|
|
#endif
|