2009-10-07 18:13:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
#ifndef GFX_GDIFONTLIST_H
|
|
|
|
#define GFX_GDIFONTLIST_H
|
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2009-10-07 18:13:40 +04:00
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#include "gfxPlatformFontList.h"
|
2012-03-30 01:08:43 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
class AutoDC // get the global device context, and auto-release it on destruction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoDC() {
|
2013-07-31 19:44:31 +04:00
|
|
|
mDC = ::GetDC(nullptr);
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoDC() {
|
2013-07-31 19:44:31 +04:00
|
|
|
::ReleaseDC(nullptr, mDC);
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HDC GetDC() {
|
|
|
|
return mDC;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
HDC mDC;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AutoSelectFont // select a font into the given DC, and auto-restore
|
|
|
|
{
|
|
|
|
public:
|
2010-03-15 12:34:25 +03:00
|
|
|
AutoSelectFont(HDC aDC, LOGFONTW *aLogFont)
|
2011-10-17 18:59:28 +04:00
|
|
|
: mOwnsFont(false)
|
2010-03-15 12:34:25 +03:00
|
|
|
{
|
2009-10-07 18:13:40 +04:00
|
|
|
mFont = ::CreateFontIndirectW(aLogFont);
|
|
|
|
if (mFont) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mOwnsFont = true;
|
2009-10-07 18:13:40 +04:00
|
|
|
mDC = aDC;
|
|
|
|
mOldFont = (HFONT)::SelectObject(aDC, mFont);
|
|
|
|
} else {
|
2013-07-31 19:44:31 +04:00
|
|
|
mOldFont = nullptr;
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-15 12:34:25 +03:00
|
|
|
AutoSelectFont(HDC aDC, HFONT aFont)
|
2011-10-17 18:59:28 +04:00
|
|
|
: mOwnsFont(false)
|
2010-03-15 12:34:25 +03:00
|
|
|
{
|
2009-10-07 18:13:40 +04:00
|
|
|
mDC = aDC;
|
|
|
|
mFont = aFont;
|
|
|
|
mOldFont = (HFONT)::SelectObject(aDC, aFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSelectFont() {
|
|
|
|
if (mOldFont) {
|
|
|
|
::SelectObject(mDC, mOldFont);
|
2010-03-15 12:34:25 +03:00
|
|
|
if (mOwnsFont) {
|
|
|
|
::DeleteObject(mFont);
|
|
|
|
}
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsValid() const {
|
2013-07-31 19:44:31 +04:00
|
|
|
return mFont != nullptr;
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HFONT GetFont() const {
|
|
|
|
return mFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-03-15 12:34:25 +03:00
|
|
|
HDC mDC;
|
|
|
|
HFONT mFont;
|
|
|
|
HFONT mOldFont;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOwnsFont;
|
2009-10-07 18:13:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of different types of fonts we support on Windows.
|
|
|
|
* These can generally be lumped in to 3 categories where we have to
|
|
|
|
* do special things: Really old fonts bitmap and vector fonts (device
|
|
|
|
* and raster), Type 1 fonts, and TrueType/OpenType fonts.
|
|
|
|
*
|
|
|
|
* This list is sorted in order from least prefered to most prefered.
|
|
|
|
* We prefer Type1 fonts over OpenType fonts to avoid falling back to
|
|
|
|
* things like Arial (opentype) when you ask for Helvetica (type1)
|
|
|
|
**/
|
|
|
|
enum gfxWindowsFontType {
|
|
|
|
GFX_FONT_TYPE_UNKNOWN = 0,
|
|
|
|
GFX_FONT_TYPE_DEVICE,
|
|
|
|
GFX_FONT_TYPE_RASTER,
|
|
|
|
GFX_FONT_TYPE_TRUETYPE,
|
|
|
|
GFX_FONT_TYPE_PS_OPENTYPE,
|
|
|
|
GFX_FONT_TYPE_TT_OPENTYPE,
|
|
|
|
GFX_FONT_TYPE_TYPE1
|
|
|
|
};
|
|
|
|
|
|
|
|
// A single member of a font family (i.e. a single face, such as Times Italic)
|
|
|
|
// represented as a LOGFONT that will resolve to the correct face.
|
|
|
|
// This replaces FontEntry from gfxWindowsFonts.h/cpp.
|
|
|
|
class GDIFontEntry : public gfxFontEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LPLOGFONTW GetLogFont() { return &mLogFont; }
|
|
|
|
|
|
|
|
nsresult ReadCMAP();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsSymbolFont();
|
2011-05-20 10:09:30 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void FillLogFont(LOGFONTW *aLogFont, uint16_t aWeight, gfxFloat aSize,
|
2012-02-14 12:24:26 +04:00
|
|
|
bool aUseCleartype);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
static gfxWindowsFontType DetermineFontType(const NEWTEXTMETRICW& metrics,
|
|
|
|
DWORD fontType)
|
|
|
|
{
|
|
|
|
gfxWindowsFontType feType;
|
|
|
|
if (metrics.ntmFlags & NTM_TYPE1)
|
|
|
|
feType = GFX_FONT_TYPE_TYPE1;
|
|
|
|
else if (metrics.ntmFlags & NTM_PS_OPENTYPE)
|
|
|
|
feType = GFX_FONT_TYPE_PS_OPENTYPE;
|
|
|
|
else if (metrics.ntmFlags & NTM_TT_OPENTYPE)
|
|
|
|
feType = GFX_FONT_TYPE_TT_OPENTYPE;
|
|
|
|
else if (fontType == TRUETYPE_FONTTYPE)
|
|
|
|
feType = GFX_FONT_TYPE_TRUETYPE;
|
|
|
|
else if (fontType == RASTER_FONTTYPE)
|
|
|
|
feType = GFX_FONT_TYPE_RASTER;
|
|
|
|
else if (fontType == DEVICE_FONTTYPE)
|
|
|
|
feType = GFX_FONT_TYPE_DEVICE;
|
|
|
|
else
|
|
|
|
feType = GFX_FONT_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
return feType;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsType1() const {
|
2009-10-07 18:13:40 +04:00
|
|
|
return (mFontType == GFX_FONT_TYPE_TYPE1);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsTrueType() const {
|
2009-10-07 18:13:40 +04:00
|
|
|
return (mFontType == GFX_FONT_TYPE_TRUETYPE ||
|
|
|
|
mFontType == GFX_FONT_TYPE_PS_OPENTYPE ||
|
|
|
|
mFontType == GFX_FONT_TYPE_TT_OPENTYPE);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool MatchesGenericFamily(const nsACString& aGeneric) const {
|
2010-02-26 02:02:54 +03:00
|
|
|
if (aGeneric.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-02-26 02:02:54 +03:00
|
|
|
}
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
// Japanese 'Mincho' fonts do not belong to FF_MODERN even if
|
|
|
|
// they are fixed pitch because they have variable stroke width.
|
|
|
|
if (mWindowsFamily == FF_ROMAN && mWindowsPitch & FIXED_PITCH) {
|
|
|
|
return aGeneric.EqualsLiteral("monospace");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Japanese 'Gothic' fonts do not belong to FF_SWISS even if
|
|
|
|
// they are variable pitch because they have constant stroke width.
|
|
|
|
if (mWindowsFamily == FF_MODERN && mWindowsPitch & VARIABLE_PITCH) {
|
|
|
|
return aGeneric.EqualsLiteral("sans-serif");
|
|
|
|
}
|
|
|
|
|
|
|
|
// All other fonts will be grouped correctly using family...
|
|
|
|
switch (mWindowsFamily) {
|
|
|
|
case FF_DONTCARE:
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-07 18:13:40 +04:00
|
|
|
case FF_ROMAN:
|
|
|
|
return aGeneric.EqualsLiteral("serif");
|
|
|
|
case FF_SWISS:
|
|
|
|
return aGeneric.EqualsLiteral("sans-serif");
|
|
|
|
case FF_MODERN:
|
|
|
|
return aGeneric.EqualsLiteral("monospace");
|
|
|
|
case FF_SCRIPT:
|
|
|
|
return aGeneric.EqualsLiteral("cursive");
|
|
|
|
case FF_DECORATIVE:
|
|
|
|
return aGeneric.EqualsLiteral("fantasy");
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SupportsLangGroup(nsIAtom* aLangGroup) const {
|
2012-03-30 01:08:43 +04:00
|
|
|
if (!aLangGroup || aLangGroup == nsGkAtoms::Unicode) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-02-26 02:02:54 +03:00
|
|
|
}
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t bit = -1;
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
/* map our langgroup names in to Windows charset bits */
|
2012-03-30 01:08:43 +04:00
|
|
|
if (aLangGroup == nsGkAtoms::x_western) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = ANSI_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::Japanese) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = SHIFTJIS_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::ko) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = HANGEUL_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::ko_xxx) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = JOHAB_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::zh_cn) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = GB2312_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::zh_tw) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = CHINESEBIG5_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::el_) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = GREEK_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::tr) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = TURKISH_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::he) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = HEBREW_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::ar) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = ARABIC_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::x_baltic) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = BALTIC_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::x_cyrillic) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = RUSSIAN_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::th) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = THAI_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::x_central_euro) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = EASTEUROPE_CHARSET;
|
2012-03-30 01:08:43 +04:00
|
|
|
} else if (aLangGroup == nsGkAtoms::x_symbol) {
|
2009-10-07 18:13:40 +04:00
|
|
|
bit = SYMBOL_CHARSET;
|
|
|
|
}
|
|
|
|
|
2010-02-26 02:02:54 +03:00
|
|
|
if (bit != -1) {
|
2010-01-15 00:31:06 +03:00
|
|
|
return mCharset.test(bit);
|
2010-02-26 02:02:54 +03:00
|
|
|
}
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool SupportsRange(uint8_t range) {
|
2010-01-15 00:31:06 +03:00
|
|
|
return mUnicodeRanges.test(range);
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SkipDuringSystemFallback() {
|
2010-06-25 16:43:10 +04:00
|
|
|
return !HasCmapTable(); // explicitly skip non-SFNT fonts
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool TestCharacterMap(uint32_t aCh);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual void SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
2012-03-28 01:38:39 +04:00
|
|
|
FontListSizes* aSizes) const;
|
|
|
|
|
2009-10-07 18:13:40 +04:00
|
|
|
// create a font entry for a font with a given name
|
2011-09-05 11:34:40 +04:00
|
|
|
static GDIFontEntry* CreateFontEntry(const nsAString& aName,
|
|
|
|
gfxWindowsFontType aFontType,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aItalic,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t aWeight, int16_t aStretch,
|
2012-07-03 14:42:07 +04:00
|
|
|
gfxUserFontData* aUserFontData,
|
|
|
|
bool aFamilyHasItalicFace);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
// create a font entry for a font referenced by its fullname
|
|
|
|
static GDIFontEntry* LoadLocalFont(const gfxProxyFontEntry &aProxyEntry,
|
2011-09-05 11:34:40 +04:00
|
|
|
const nsAString& aFullname);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mWindowsFamily;
|
|
|
|
uint8_t mWindowsPitch;
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
gfxWindowsFontType mFontType;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mForceGDI : 1;
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2012-07-03 14:42:07 +04:00
|
|
|
// For src:local user-fonts, we keep track of whether the platform family
|
|
|
|
// contains an italic face, because in this case we can't safely ask GDI
|
|
|
|
// to create synthetic italics (oblique) via the LOGFONT.
|
|
|
|
// (For other types of font, this is just set to false.)
|
|
|
|
bool mFamilyHasItalicFace : 1;
|
|
|
|
|
2010-01-15 00:31:06 +03:00
|
|
|
gfxSparseBitSet mCharset;
|
|
|
|
gfxSparseBitSet mUnicodeRanges;
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class gfxWindowsFont;
|
|
|
|
|
|
|
|
GDIFontEntry(const nsAString& aFaceName, gfxWindowsFontType aFontType,
|
2012-08-22 19:56:38 +04:00
|
|
|
bool aItalic, uint16_t aWeight, int16_t aStretch,
|
2012-07-03 14:42:07 +04:00
|
|
|
gfxUserFontData *aUserFontData, bool aFamilyHasItalicFace);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2010-06-09 04:33:13 +04:00
|
|
|
void InitLogFont(const nsAString& aName, gfxWindowsFontType aFontType);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBold);
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2013-05-16 20:29:20 +04:00
|
|
|
virtual nsresult CopyFontTable(uint32_t aTableTag,
|
|
|
|
FallibleTArray<uint8_t>& aBuffer) MOZ_OVERRIDE;
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
LOGFONTW mLogFont;
|
|
|
|
};
|
|
|
|
|
|
|
|
// a single font family, referencing one or more faces
|
|
|
|
class GDIFontFamily : public gfxFontFamily
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GDIFontFamily(nsAString &aName) :
|
|
|
|
gfxFontFamily(aName) {}
|
|
|
|
|
|
|
|
virtual void FindStyleVariations();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static int CALLBACK FamilyAddStylesProc(const ENUMLOGFONTEXW *lpelfe,
|
|
|
|
const NEWTEXTMETRICEXW *nmetrics,
|
|
|
|
DWORD fontType, LPARAM data);
|
|
|
|
};
|
|
|
|
|
|
|
|
class gfxGDIFontList : public gfxPlatformFontList {
|
|
|
|
public:
|
|
|
|
static gfxGDIFontList* PlatformFontList() {
|
|
|
|
return static_cast<gfxGDIFontList*>(sPlatformFontList);
|
|
|
|
}
|
|
|
|
|
2010-11-08 14:02:27 +03:00
|
|
|
// initialize font lists
|
|
|
|
virtual nsresult InitFontList();
|
|
|
|
|
2012-12-19 13:42:25 +04:00
|
|
|
virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName);
|
|
|
|
|
|
|
|
virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t *aFontData, uint32_t aLength);
|
2009-10-07 18:13:40 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool ResolveFontName(const nsAString& aFontName,
|
2009-10-07 18:13:40 +04:00
|
|
|
nsAString& aResolvedFontName);
|
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual void SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
2012-03-28 01:38:39 +04:00
|
|
|
FontListSizes* aSizes) const;
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual void SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
2012-03-28 01:38:39 +04:00
|
|
|
FontListSizes* aSizes) const;
|
|
|
|
|
2009-10-07 18:13:40 +04:00
|
|
|
private:
|
|
|
|
friend class gfxWindowsPlatform;
|
|
|
|
|
|
|
|
gfxGDIFontList();
|
|
|
|
|
|
|
|
nsresult GetFontSubstitutes();
|
|
|
|
|
|
|
|
static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *lpelfe,
|
|
|
|
NEWTEXTMETRICEXW *lpntme,
|
|
|
|
DWORD fontType,
|
|
|
|
LPARAM lParam);
|
|
|
|
|
2012-03-28 01:38:39 +04:00
|
|
|
typedef nsRefPtrHashtable<nsStringHashKey, gfxFontFamily> FontTable;
|
2009-10-07 18:13:40 +04:00
|
|
|
|
|
|
|
FontTable mFontSubstitutes;
|
|
|
|
nsTArray<nsString> mNonExistingFonts;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_GDIFONTLIST_H */
|