Change fixedWidth to fixedPitch and implement on Windows.

https://codereview.appspot.com/7954044/


git-svn-id: http://skia.googlecode.com/svn/trunk@8372 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bungeman@google.com 2013-03-25 19:36:11 +00:00
parent 2daa365123
commit fe74765f0d
8 changed files with 58 additions and 51 deletions

View File

@ -60,9 +60,10 @@ public:
*/
bool isItalic() const { return (fStyle & kItalic) != 0; }
/** Returns true if the typeface is fixed-width
/** Returns true if the typeface claims to be fixed-pitch.
* This is a style bit, advance widths may vary even if this returns true.
*/
bool isFixedWidth() const { return fIsFixedWidth; }
bool isFixedPitch() const { return fIsFixedPitch; }
/** Return a 32bit value for this typeface, unique for the underlying font
data. Will never return 0.
@ -205,9 +206,12 @@ public:
protected:
/** uniqueID must be unique and non-zero
*/
SkTypeface(Style style, SkFontID uniqueID, bool isFixedWidth = false);
SkTypeface(Style style, SkFontID uniqueID, bool isFixedPitch = false);
virtual ~SkTypeface();
/** Sets the fixedPitch bit. If used, must be called in the constructor. */
void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; }
friend class SkScalerContext;
static SkTypeface* GetDefaultTypeface();
@ -229,7 +233,7 @@ protected:
private:
SkFontID fUniqueID;
Style fStyle;
bool fIsFixedWidth;
bool fIsFixedPitch;
friend class SkPaint;
friend class SkGlyphCache; // GetDefaultTypeface

View File

@ -20,8 +20,8 @@ SK_DEFINE_INST_COUNT(SkTypeface)
static int32_t gTypefaceCounter;
#endif
SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedWidth)
: fUniqueID(fontID), fStyle(style), fIsFixedWidth(isFixedWidth) {
SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedPitch)
: fUniqueID(fontID), fStyle(style), fIsFixedPitch(isFixedPitch) {
#ifdef TRACE_LIFECYCLE
SkDebugf("SkTypeface: create %p fontID %d total %d\n",
this, fontID, ++gTypefaceCounter);

View File

@ -1310,7 +1310,7 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx,
ability to extract the name+style from a stream, using FreeType's api.
*/
bool find_name_and_attributes(SkStream* stream, SkString* name,
SkTypeface::Style* style, bool* isFixedWidth) {
SkTypeface::Style* style, bool* isFixedPitch) {
FT_Library library;
if (FT_Init_FreeType(&library)) {
return false;
@ -1357,8 +1357,8 @@ bool find_name_and_attributes(SkStream* stream, SkString* name,
if (style) {
*style = (SkTypeface::Style) tempStyle;
}
if (isFixedWidth) {
*isFixedWidth = FT_IS_FIXED_WIDTH(face);
if (isFixedPitch) {
*isFixedPitch = FT_IS_FIXED_WIDTH(face);
}
FT_Done_Face(face);

View File

@ -47,8 +47,8 @@ private:
class SkTypeface_FreeType : public SkTypeface {
protected:
SkTypeface_FreeType(Style style, SkFontID uniqueID, bool isFixedWidth)
: INHERITED(style, uniqueID, isFixedWidth) {}
SkTypeface_FreeType(Style style, SkFontID uniqueID, bool isFixedPitch)
: INHERITED(style, uniqueID, isFixedPitch) {}
virtual SkScalerContext* onCreateScalerContext(
const SkDescriptor*) const SK_OVERRIDE;

View File

@ -32,7 +32,7 @@ static const char* gTestFallbackConfigFile = NULL;
static const char* gTestFontFilePrefix = NULL;
bool find_name_and_attributes(SkStream* stream, SkString* name,
SkTypeface::Style* style, bool* isFixedWidth);
SkTypeface::Style* style, bool* isFixedPitch);
static void GetFullPathForSysFonts(SkString* full, const char name[]) {
if (gTestFontFilePrefix) {
@ -284,8 +284,8 @@ static void remove_from_names(FamilyRec* emptyFamily) {
class FamilyTypeface : public SkTypeface_FreeType {
public:
FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember,
bool isFixedWidth)
: INHERITED(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) {
bool isFixedPitch)
: INHERITED(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedPitch) {
fIsSysFont = sysFont;
// our caller has acquired the gFamilyHeadAndNameListMutex so this is safe
@ -330,8 +330,8 @@ private:
class StreamTypeface : public FamilyTypeface {
public:
StreamTypeface(Style style, bool sysFont, SkTypeface* familyMember,
SkStream* stream, bool isFixedWidth)
: INHERITED(style, sysFont, familyMember, isFixedWidth) {
SkStream* stream, bool isFixedPitch)
: INHERITED(style, sysFont, familyMember, isFixedPitch) {
SkASSERT(stream);
stream->ref();
fStream = stream;
@ -363,8 +363,8 @@ private:
class FileTypeface : public FamilyTypeface {
public:
FileTypeface(Style style, bool sysFont, SkTypeface* familyMember,
const char path[], bool isFixedWidth)
: INHERITED(style, sysFont, familyMember, isFixedWidth) {
const char path[], bool isFixedPitch)
: INHERITED(style, sysFont, familyMember, isFixedPitch) {
SkString fullpath;
if (sysFont) {
@ -403,13 +403,13 @@ private:
static bool get_name_and_style(const char path[], SkString* name,
SkTypeface::Style* style,
bool* isFixedWidth, bool isExpected) {
bool* isFixedPitch, bool isExpected) {
SkString fullpath;
GetFullPathForSysFonts(&fullpath, path);
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(fullpath.c_str()));
if (stream.get()) {
return find_name_and_attributes(stream, name, style, isFixedWidth);
return find_name_and_attributes(stream, name, style, isFixedPitch);
} else {
if (isExpected) {
SkDebugf("---- failed to open <%s> as a font", fullpath.c_str());
@ -591,14 +591,14 @@ static void init_system_fonts() {
firstInFamily = NULL;
}
bool isFixedWidth;
bool isFixedPitch;
SkString name;
SkTypeface::Style style;
// we expect all the fonts, except the "fallback" fonts
bool isExpected = (rec[i].fNames != gFBNames);
if (!get_name_and_style(rec[i].fFileName, &name, &style,
&isFixedWidth, isExpected)) {
&isFixedPitch, isExpected)) {
// We need to increase gUniqueFontID here so that the unique id of
// each font matches its index in gSystemFonts array, as expected
// by find_uniqueID.
@ -611,7 +611,7 @@ static void init_system_fonts() {
true, // system-font (cannot delete)
firstInFamily, // what family to join
rec[i].fFileName,
isFixedWidth) // filename
isFixedPitch) // filename
);
#if SK_DEBUG_FONTS
SkDebugf("---- SkTypeface[%d] %s fontID %d",
@ -698,11 +698,11 @@ static void reload_fallback_fonts() {
if (family->fFileNames[j]) {
// ensure the fallback font exists before adding it to the list
bool isFixedWidth;
bool isFixedPitch;
SkString name;
SkTypeface::Style style;
if (!get_name_and_style(family->fFileNames[j], &name, &style,
&isFixedWidth, false)) {
&isFixedPitch, false)) {
continue;
}
@ -854,15 +854,15 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
return NULL;
}
bool isFixedWidth;
bool isFixedPitch;
SkTypeface::Style style;
if (find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
if (find_name_and_attributes(stream, NULL, &style, &isFixedPitch)) {
SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
// Make sure system fonts are loaded to comply with the assumption of
// unique id offset by one in find_uniqueID.
load_system_fonts();
return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWidth));
return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedPitch));
} else {
return NULL;
}

View File

@ -26,7 +26,7 @@
#endif
bool find_name_and_attributes(SkStream* stream, SkString* name,
SkTypeface::Style* style, bool* isFixedWidth);
SkTypeface::Style* style, bool* isFixedPitch);
///////////////////////////////////////////////////////////////////////////////
@ -231,8 +231,8 @@ static void remove_from_names(FamilyRec* emptyFamily) {
class FamilyTypeface : public SkTypeface_FreeType {
public:
FamilyTypeface(Style style, bool sysFont, FamilyRec* family, bool isFixedWidth)
: INHERITED(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) {
FamilyTypeface(Style style, bool sysFont, FamilyRec* family, bool isFixedPitch)
: INHERITED(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedPitch) {
fIsSysFont = sysFont;
SkAutoMutexAcquire ac(gFamilyMutex);
@ -293,8 +293,8 @@ private:
class StreamTypeface : public FamilyTypeface {
public:
StreamTypeface(Style style, bool sysFont, FamilyRec* family,
SkStream* stream, bool isFixedWidth)
: INHERITED(style, sysFont, family, isFixedWidth) {
SkStream* stream, bool isFixedPitch)
: INHERITED(style, sysFont, family, isFixedPitch) {
stream->ref();
fStream = stream;
}
@ -320,8 +320,8 @@ private:
class FileTypeface : public FamilyTypeface {
public:
FileTypeface(Style style, bool sysFont, FamilyRec* family,
const char path[], bool isFixedWidth)
: INHERITED(style, sysFont, family, isFixedWidth) {
const char path[], bool isFixedPitch)
: INHERITED(style, sysFont, family, isFixedPitch) {
fPath.set(path);
}
@ -349,10 +349,10 @@ private:
///////////////////////////////////////////////////////////////////////////////
static bool get_name_and_style(const char path[], SkString* name,
SkTypeface::Style* style, bool* isFixedWidth) {
SkTypeface::Style* style, bool* isFixedPitch) {
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
if (stream.get()) {
return find_name_and_attributes(stream, name, style, isFixedWidth);
return find_name_and_attributes(stream, name, style, isFixedPitch);
} else {
SkDebugf("---- failed to open <%s> as a font\n", path);
return false;
@ -372,11 +372,11 @@ static void load_directory_fonts(const SkString& directory, unsigned int* count)
SkString filename(directory);
filename.append(name);
bool isFixedWidth;
bool isFixedPitch;
SkString realname;
SkTypeface::Style style = SkTypeface::kNormal; // avoid uninitialized warning
if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixedWidth)) {
if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixedPitch)) {
SkDebugf("------ can't load <%s> as a font\n", filename.c_str());
continue;
}
@ -392,7 +392,7 @@ static void load_directory_fonts(const SkString& directory, unsigned int* count)
true, // system-font (cannot delete)
family, // what family to join
filename.c_str(),
isFixedWidth) // filename
isFixedPitch) // filename
);
if (NULL == family) {
@ -508,10 +508,10 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
return NULL;
}
bool isFixedWidth;
bool isFixedPitch;
SkTypeface::Style style;
if (find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWidth));
if (find_name_and_attributes(stream, NULL, &style, &isFixedPitch)) {
return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedPitch));
} else {
return NULL;
}

View File

@ -350,7 +350,7 @@ Offscreen::Offscreen() : fRGBSpace(NULL), fCG(NULL) {
///////////////////////////////////////////////////////////////////////////////
static SkTypeface::Style computeStyleBits(CTFontRef font, bool* isMonospace) {
static SkTypeface::Style computeStyleBits(CTFontRef font, bool* isFixedPitch) {
unsigned style = SkTypeface::kNormal;
CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
@ -360,8 +360,8 @@ static SkTypeface::Style computeStyleBits(CTFontRef font, bool* isMonospace) {
if (traits & kCTFontItalicTrait) {
style |= SkTypeface::kItalic;
}
if (isMonospace) {
*isMonospace = (traits & kCTFontMonoSpaceTrait) != 0;
if (isFixedPitch) {
*isFixedPitch = (traits & kCTFontMonoSpaceTrait) != 0;
}
return (SkTypeface::Style)style;
}
@ -396,9 +396,9 @@ static SkFontID CTFontRef_to_SkFontID(CTFontRef fontRef) {
class SkTypeface_Mac : public SkTypeface {
public:
SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isMonospace,
SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch,
CTFontRef fontRef, const char name[])
: SkTypeface(style, fontID, isMonospace)
: SkTypeface(style, fontID, isFixedPitch)
, fName(name)
, fFontRef(fontRef) // caller has already called CFRetain for us
{
@ -429,11 +429,11 @@ private:
static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) {
SkASSERT(fontRef);
bool isMonospace;
SkTypeface::Style style = computeStyleBits(fontRef, &isMonospace);
bool isFixedPitch;
SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch);
SkFontID fontID = CTFontRef_to_SkFontID(fontRef);
return new SkTypeface_Mac(style, fontID, isMonospace, fontRef, name);
return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name);
}
static SkTypeface* NewFromName(const char familyName[], SkTypeface::Style theStyle) {

View File

@ -189,6 +189,9 @@ public:
::DeleteObject(font);
}
// The fixed pitch bit is set if the font is *not* fixed pitch.
this->setIsFixedPitch((textMetric.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0);
// Used a logfont on a memory context, should never get a device font.
// Therefore all TMPF_DEVICE will be PostScript (cubic) fonts.
fCanBeLCD = !((textMetric.tmPitchAndFamily & TMPF_VECTOR) &&