Merge FontPlatformDataHarfBuzz into FontPlatformData

From WebKit legacy we have two redundant copies of this file.
In order for switching shapers on mac, we need to fuse these files again. 
This is part two of the merge,
after the headers were merged in r181655 / ad011a9df.

BUG=334269

R=eae

Review URL: https://codereview.chromium.org/550083005

git-svn-id: svn://svn.chromium.org/blink/trunk@181754 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 91e7c4fc
...@@ -225,7 +225,6 @@ component("platform") { ...@@ -225,7 +225,6 @@ component("platform") {
if (is_mac) { if (is_mac) {
sources -= [ sources -= [
"fonts/harfbuzz/FontHarfBuzz.cpp", "fonts/harfbuzz/FontHarfBuzz.cpp",
"fonts/harfbuzz/FontPlatformDataHarfBuzz.cpp",
"fonts/harfbuzz/HarfBuzzFaceSkia.cpp", "fonts/harfbuzz/HarfBuzzFaceSkia.cpp",
"fonts/opentype/OpenTypeTypes.h", "fonts/opentype/OpenTypeTypes.h",
"fonts/opentype/OpenTypeVerticalData.cpp", "fonts/opentype/OpenTypeVerticalData.cpp",
...@@ -262,9 +261,6 @@ component("platform") { ...@@ -262,9 +261,6 @@ component("platform") {
] ]
} else { } else {
sources -= [ sources -= [
# FIXME: We will eventually compile this too, but for now it's
# only used on mac.
"fonts/FontPlatformData.cpp",
"fonts/harfbuzz/HarfBuzzFaceCoreText.cpp", "fonts/harfbuzz/HarfBuzzFaceCoreText.cpp",
"geometry/cg/FloatPointCG.cpp", "geometry/cg/FloatPointCG.cpp",
"geometry/cg/FloatRectCG.cpp", "geometry/cg/FloatRectCG.cpp",
......
...@@ -252,7 +252,6 @@ ...@@ -252,7 +252,6 @@
'sources/': [ 'sources/': [
# Cherry-pick files excluded by the broader regular expressions above. # Cherry-pick files excluded by the broader regular expressions above.
['include', 'fonts/harfbuzz/FontHarfBuzz\\.cpp$'], ['include', 'fonts/harfbuzz/FontHarfBuzz\\.cpp$'],
['include', 'fonts/harfbuzz/FontPlatformDataHarfBuzz\\.cpp$'],
['include', 'fonts/harfbuzz/HarfBuzzFace\\.(cpp|h)$'], ['include', 'fonts/harfbuzz/HarfBuzzFace\\.(cpp|h)$'],
['include', 'fonts/harfbuzz/HarfBuzzFaceSkia\\.cpp$'], ['include', 'fonts/harfbuzz/HarfBuzzFaceSkia\\.cpp$'],
['include', 'fonts/harfbuzz/HarfBuzzShaper\\.(cpp|h)$'], ['include', 'fonts/harfbuzz/HarfBuzzShaper\\.(cpp|h)$'],
...@@ -361,9 +360,6 @@ ...@@ -361,9 +360,6 @@
['exclude', 'geometry/cg/'], ['exclude', 'geometry/cg/'],
['exclude', 'scroll/ScrollbarThemeMac'], ['exclude', 'scroll/ScrollbarThemeMac'],
# FIXME: We will eventually compile this too, but for now it's
# only used on mac.
['exclude', 'fonts/FontPlatformData\\.cpp$'],
['exclude', 'fonts/harfbuzz/HarfBuzzFaceCoreText\\.cpp$'], ['exclude', 'fonts/harfbuzz/HarfBuzzFaceCoreText\\.cpp$'],
], ],
}], }],
......
...@@ -388,7 +388,6 @@ ...@@ -388,7 +388,6 @@
'fonts/android/FontCacheAndroid.cpp', 'fonts/android/FontCacheAndroid.cpp',
'fonts/cocoa/FontPlatformDataCocoa.mm', 'fonts/cocoa/FontPlatformDataCocoa.mm',
'fonts/harfbuzz/FontHarfBuzz.cpp', 'fonts/harfbuzz/FontHarfBuzz.cpp',
'fonts/harfbuzz/FontPlatformDataHarfBuzz.cpp',
'fonts/harfbuzz/HarfBuzzFace.cpp', 'fonts/harfbuzz/HarfBuzzFace.cpp',
'fonts/harfbuzz/HarfBuzzFace.h', 'fonts/harfbuzz/HarfBuzzFace.h',
'fonts/harfbuzz/HarfBuzzFaceCoreText.cpp', 'fonts/harfbuzz/HarfBuzzFaceCoreText.cpp',
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "wtf/text/WTFString.h" #include "wtf/text/WTFString.h"
#if OS(MACOSX) #if OS(MACOSX)
#include "platform/fonts/harfbuzz/HarfBuzzFace.h" #include "third_party/skia/include/ports/SkTypeface_mac.h"
#endif #endif
using namespace std; using namespace std;
...@@ -36,53 +36,125 @@ using namespace std; ...@@ -36,53 +36,125 @@ using namespace std;
namespace blink { namespace blink {
FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
: m_textSize(0) : m_typeface(nullptr)
#if !OS(WIN)
, m_family(CString())
#endif
, m_textSize(0)
, m_syntheticBold(false) , m_syntheticBold(false)
, m_syntheticItalic(false) , m_syntheticItalic(false)
, m_orientation(Horizontal) , m_orientation(Horizontal)
#if OS(MACOSX)
, m_isColorBitmapFont(false) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false) , m_isCompositeFontReference(false)
#endif
, m_widthVariant(RegularWidth) , m_widthVariant(RegularWidth)
#if OS(MACOSX) #if OS(MACOSX)
, m_font(nullptr) , m_font(nullptr)
#endif #endif
, m_isHashTableDeletedValue(true) , m_isHashTableDeletedValue(true)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(false)
#endif
{ {
} }
FontPlatformData::FontPlatformData() FontPlatformData::FontPlatformData()
: m_textSize(0) : m_typeface(nullptr)
#if !OS(WIN)
, m_family(CString())
#endif
, m_textSize(0)
, m_syntheticBold(false) , m_syntheticBold(false)
, m_syntheticItalic(false) , m_syntheticItalic(false)
, m_orientation(Horizontal) , m_orientation(Horizontal)
#if OS(MACOSX)
, m_isColorBitmapFont(false) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false) , m_isCompositeFontReference(false)
#endif
, m_widthVariant(RegularWidth) , m_widthVariant(RegularWidth)
#if OS(MACOSX) #if OS(MACOSX)
, m_font(nullptr) , m_font(nullptr)
#endif #endif
, m_isHashTableDeletedValue(false) , m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(false)
#endif
{ {
} }
FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant) FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_textSize(size) : m_typeface(nullptr)
#if !OS(WIN)
, m_family(CString())
#endif
, m_textSize(size)
, m_syntheticBold(syntheticBold) , m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic) , m_syntheticItalic(syntheticItalic)
, m_orientation(orientation) , m_orientation(orientation)
#if OS(MACOSX)
, m_isColorBitmapFont(false) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false) , m_isCompositeFontReference(false)
#endif
, m_widthVariant(widthVariant) , m_widthVariant(widthVariant)
#if OS(MACOSX) #if OS(MACOSX)
, m_font(nullptr) , m_font(nullptr)
#endif #endif
, m_isHashTableDeletedValue(false) , m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(false)
#endif
{ {
} }
FontPlatformData::FontPlatformData(const FontPlatformData& source)
: m_typeface(source.m_typeface)
#if !OS(WIN)
, m_family(source.m_family)
#endif
, m_textSize(source.m_textSize)
, m_syntheticBold(source.m_syntheticBold)
, m_syntheticItalic(source.m_syntheticItalic)
, m_orientation(source.m_orientation)
#if OS(MACOSX)
, m_isColorBitmapFont(source.m_isColorBitmapFont)
, m_isCompositeFontReference(source.m_isCompositeFontReference)
#endif
, m_widthVariant(source.m_widthVariant)
#if !OS(MACOSX)
, m_style(source.m_style)
#endif
, m_harfBuzzFace(nullptr)
, m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(source.m_paintTextFlags)
, m_minSizeForAntiAlias(source.m_minSizeForAntiAlias)
, m_minSizeForSubpixel(source.m_minSizeForSubpixel)
, m_useSubpixelPositioning(source.m_useSubpixelPositioning)
#endif
{
#if OS(MACOSX)
platformDataInit(source);
#endif
}
#if OS(MACOSX) #if OS(MACOSX)
FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant) FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_textSize(size) : m_typeface(nullptr)
#if !OS(WIN)
, m_family(CString())
#endif
, m_textSize(size)
, m_syntheticBold(syntheticBold) , m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic) , m_syntheticItalic(syntheticItalic)
, m_orientation(orientation) , m_orientation(orientation)
...@@ -94,19 +166,58 @@ FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB ...@@ -94,19 +166,58 @@ FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB
, m_isHashTableDeletedValue(false) , m_isHashTableDeletedValue(false)
{ {
} }
#else
FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, bool subpixelTextPosition)
: m_typeface(tf)
#if !OS(WIN)
, m_family(family)
#endif
, m_textSize(textSize)
, m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation)
, m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(subpixelTextPosition)
#endif #endif
{
querySystemForRenderStyle(subpixelTextPosition);
}
FontPlatformData::FontPlatformData(const FontPlatformData& source)
: m_textSize(source.m_textSize) FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
, m_syntheticBold(source.m_syntheticBold) : m_typeface(src.m_typeface)
, m_syntheticItalic(source.m_syntheticItalic) #if !OS(WIN)
, m_orientation(source.m_orientation) , m_family(src.m_family)
, m_isColorBitmapFont(source.m_isColorBitmapFont) #endif
, m_isCompositeFontReference(source.m_isCompositeFontReference) , m_textSize(textSize)
, m_widthVariant(source.m_widthVariant) , m_syntheticBold(src.m_syntheticBold)
, m_syntheticItalic(src.m_syntheticItalic)
, m_orientation(src.m_orientation)
, m_harfBuzzFace(nullptr)
, m_isHashTableDeletedValue(false) , m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(src.m_paintTextFlags)
, m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
, m_minSizeForSubpixel(src.m_minSizeForSubpixel)
, m_useSubpixelPositioning(src.m_useSubpixelPositioning)
#endif
{ {
platformDataInit(source); querySystemForRenderStyle(FontDescription::subpixelPositioning());
}
#endif
FontPlatformData::~FontPlatformData()
{
#if OS(MACOSX)
if (m_font)
CFRelease(m_font);
#endif
} }
const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other) const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other)
...@@ -115,21 +226,56 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe ...@@ -115,21 +226,56 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
if (this == &other) if (this == &other)
return *this; return *this;
m_typeface = other.m_typeface;
#if !OS(WIN)
m_family = other.m_family;
#endif
m_textSize = other.m_textSize;
m_syntheticBold = other.m_syntheticBold; m_syntheticBold = other.m_syntheticBold;
m_syntheticItalic = other.m_syntheticItalic; m_syntheticItalic = other.m_syntheticItalic;
m_harfBuzzFace = nullptr;
m_orientation = other.m_orientation; m_orientation = other.m_orientation;
m_textSize = other.m_textSize;
m_widthVariant = other.m_widthVariant; m_widthVariant = other.m_widthVariant;
#if OS(MACOSX)
m_isColorBitmapFont = other.m_isColorBitmapFont; m_isColorBitmapFont = other.m_isColorBitmapFont;
m_isCompositeFontReference = other.m_isCompositeFontReference; m_isCompositeFontReference = other.m_isCompositeFontReference;
#else
m_style = other.m_style;
#endif
m_widthVariant = other.m_widthVariant;
#if OS(WIN)
m_paintTextFlags = 0;
m_minSizeForAntiAlias = other.m_minSizeForAntiAlias;
m_minSizeForSubpixel = other.m_minSizeForSubpixel;
m_useSubpixelPositioning = other.m_useSubpixelPositioning;
#endif
#if OS(MACOSX)
return platformDataAssign(other); return platformDataAssign(other);
#else
return *this;
#endif
} }
bool FontPlatformData::operator==(const FontPlatformData& a) const bool FontPlatformData::operator==(const FontPlatformData& a) const
{ {
// If either of the typeface pointers are null then we test for pointer
// equality. Otherwise, we call SkTypeface::Equal on the valid pointers.
bool typefacesEqual = false;
#if !OS(MACOSX)
if (!m_typeface || !a.m_typeface)
typefacesEqual = m_typeface == a.m_typeface;
else
typefacesEqual = SkTypeface::Equal(m_typeface.get(), a.m_typeface.get());
#else
if (m_font || a.m_font)
typefacesEqual = m_font == a.m_font;
else
typefacesEqual = m_cgFont == a.m_cgFont;
#endif
return platformIsEqual(a) return typefacesEqual
&& m_textSize == a.m_textSize && m_textSize == a.m_textSize
&& m_isHashTableDeletedValue == a.m_isHashTableDeletedValue && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue
&& m_syntheticBold == a.m_syntheticBold && m_syntheticBold == a.m_syntheticBold
...@@ -137,11 +283,57 @@ bool FontPlatformData::operator==(const FontPlatformData& a) const ...@@ -137,11 +283,57 @@ bool FontPlatformData::operator==(const FontPlatformData& a) const
&& m_orientation == a.m_orientation && m_orientation == a.m_orientation
#if !OS(MACOSX) #if !OS(MACOSX)
&& m_style == a.m_style && m_style == a.m_style
#endif #else
&& m_isColorBitmapFont == a.m_isColorBitmapFont && m_isColorBitmapFont == a.m_isColorBitmapFont
&& m_isCompositeFontReference == a.m_isCompositeFontReference && m_isCompositeFontReference == a.m_isCompositeFontReference
#endif
&& m_widthVariant == a.m_widthVariant; && m_widthVariant == a.m_widthVariant;
} }
SkFontID FontPlatformData::uniqueID() const
{
return typeface()->uniqueID();
}
String FontPlatformData::fontFamilyName() const
{
// FIXME(crbug.com/326582): come up with a proper way of handling SVG.
if (!this->typeface())
return "";
SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createFamilyNameIterator();
SkTypeface::LocalizedString localizedString;
while (fontFamilyIterator->next(&localizedString) && !localizedString.fString.size()) { }
fontFamilyIterator->unref();
return String(localizedString.fString.c_str());
}
bool FontPlatformData::isFixedPitch() const
{
return typeface() && typeface()->isFixedPitch();
}
SkTypeface* FontPlatformData::typeface() const
{
#if OS(MACOSX)
if (!m_typeface)
m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont()));
#endif
return m_typeface.get();
}
HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{
#if OS(MACOSX)
CTFontRef font = ctFont();
// Keeping the decision not to pass AAT font to HarfBuzz for now,
// until we switch to HarfBuzz as a shaper for all cases.
if (isAATFont(font))
return 0;
#endif
if (!m_harfBuzzFace)
m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this), uniqueID());
return m_harfBuzzFace.get();
}
} // namespace blink } // namespace blink
...@@ -75,13 +75,12 @@ public: ...@@ -75,13 +75,12 @@ public:
FontPlatformData(WTF::HashTableDeletedValueType); FontPlatformData(WTF::HashTableDeletedValueType);
FontPlatformData(); FontPlatformData();
FontPlatformData(const FontPlatformData&); FontPlatformData(const FontPlatformData&);
#if OS(MACOSX)
FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth); FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
#if OS(MACOSX)
FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticItalic = false, FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticItalic = false,
FontOrientation = Horizontal, FontWidthVariant = RegularWidth); FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant); FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant);
#else #else
FontPlatformData(float textSize, bool syntheticBold, bool syntheticItalic);
FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subpixelTextPosition = defaultUseSubpixelPositioning()); FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subpixelTextPosition = defaultUseSubpixelPositioning());
FontPlatformData(const FontPlatformData& src, float textSize); FontPlatformData(const FontPlatformData& src, float textSize);
#endif #endif
...@@ -120,6 +119,7 @@ public: ...@@ -120,6 +119,7 @@ public:
void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheticItalic; } void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheticItalic; }
bool operator==(const FontPlatformData&) const; bool operator==(const FontPlatformData&) const;
const FontPlatformData& operator=(const FontPlatformData&); const FontPlatformData& operator=(const FontPlatformData&);
bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; } bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; }
#if OS(WIN) #if OS(WIN)
void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; } void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; }
...@@ -167,10 +167,9 @@ private: ...@@ -167,10 +167,9 @@ private:
// The caller is responsible for calling CFRelease() on this parameter when done with it. // The caller is responsible for calling CFRelease() on this parameter when done with it.
// * cgFont - CGFontRef representing the input font at the specified point size. // * cgFont - CGFontRef representing the input font at the specified point size.
void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&);
bool platformIsEqual(const FontPlatformData&) const;
void platformDataInit(const FontPlatformData&); void platformDataInit(const FontPlatformData&);
const FontPlatformData& platformDataAssign(const FontPlatformData&); const FontPlatformData& platformDataAssign(const FontPlatformData&);
bool isAATFont(CTFontRef) const;
#endif #endif
mutable RefPtr<SkTypeface> m_typeface; mutable RefPtr<SkTypeface> m_typeface;
...@@ -186,8 +185,8 @@ public: ...@@ -186,8 +185,8 @@ public:
#if OS(MACOSX) #if OS(MACOSX)
bool m_isColorBitmapFont; bool m_isColorBitmapFont;
bool m_isCompositeFontReference; bool m_isCompositeFontReference;
FontWidthVariant m_widthVariant;
#endif #endif
FontWidthVariant m_widthVariant;
private: private:
#if OS(MACOSX) #if OS(MACOSX)
NSFont* m_font; NSFont* m_font;
......
...@@ -28,10 +28,8 @@ ...@@ -28,10 +28,8 @@
#import <AvailabilityMacros.h> #import <AvailabilityMacros.h>
#import <wtf/text/WTFString.h> #import <wtf/text/WTFString.h>
#if OS(MACOSX)
#import "platform/fonts/harfbuzz/HarfBuzzFace.h" #import "platform/fonts/harfbuzz/HarfBuzzFace.h"
#include "third_party/skia/include/ports/SkTypeface_mac.h" #include "third_party/skia/include/ports/SkTypeface_mac.h"
#endif
namespace blink { namespace blink {
...@@ -79,24 +77,16 @@ FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol ...@@ -79,24 +77,16 @@ FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
m_cgFont.adoptCF(cgFont); m_cgFont.adoptCF(cgFont);
} }
FontPlatformData:: ~FontPlatformData()
{
if (m_font && m_font != reinterpret_cast<NSFont *>(-1))
CFRelease(m_font);
}
void FontPlatformData::platformDataInit(const FontPlatformData& f) void FontPlatformData::platformDataInit(const FontPlatformData& f)
{ {
m_font = f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1) ? [f.m_font retain] : f.m_font; m_font = f.m_font ? [f.m_font retain] : f.m_font;
m_cgFont = f.m_cgFont; m_cgFont = f.m_cgFont;
m_CTFont = f.m_CTFont; m_CTFont = f.m_CTFont;
#if OS(MACOSX)
m_inMemoryFont = f.m_inMemoryFont; m_inMemoryFont = f.m_inMemoryFont;
m_harfBuzzFace = f.m_harfBuzzFace; m_harfBuzzFace = f.m_harfBuzzFace;
m_typeface = f.m_typeface; m_typeface = f.m_typeface;
#endif
} }
const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformData& f) const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformData& f)
...@@ -104,31 +94,24 @@ const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD ...@@ -104,31 +94,24 @@ const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD
m_cgFont = f.m_cgFont; m_cgFont = f.m_cgFont;
if (m_font == f.m_font) if (m_font == f.m_font)
return *this; return *this;
if (f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1)) if (f.m_font)
CFRetain(f.m_font); CFRetain(f.m_font);
if (m_font && m_font != reinterpret_cast<NSFont *>(-1)) if (m_font)
CFRelease(m_font); CFRelease(m_font);
m_font = f.m_font; m_font = f.m_font;
m_CTFont = f.m_CTFont; m_CTFont = f.m_CTFont;
#if OS(MACOSX)
m_inMemoryFont = f.m_inMemoryFont; m_inMemoryFont = f.m_inMemoryFont;
m_harfBuzzFace = f.m_harfBuzzFace; m_harfBuzzFace = f.m_harfBuzzFace;
m_typeface = f.m_typeface; m_typeface = f.m_typeface;
#endif
return *this; return *this;
} }
bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
{
if (m_font || other.m_font)
return m_font == other.m_font;
return m_cgFont == other.m_cgFont;
}
void FontPlatformData::setFont(NSFont *font) void FontPlatformData::setFont(NSFont *font)
{ {
ASSERT_ARG(font, font); ASSERT_ARG(font, font);
ASSERT(m_font != reinterpret_cast<NSFont *>(-1));
if (m_font == font) if (m_font == font)
return; return;
...@@ -143,7 +126,6 @@ void FontPlatformData::setFont(NSFont *font) ...@@ -143,7 +126,6 @@ void FontPlatformData::setFont(NSFont *font)
NSFont* loadedFont = 0; NSFont* loadedFont = 0;
loadFont(m_font, m_textSize, loadedFont, cgFont); loadFont(m_font, m_textSize, loadedFont, cgFont);
#if OS(MACOSX)
// If loadFont replaced m_font with a fallback font, then release the // If loadFont replaced m_font with a fallback font, then release the
// previous font to counter the retain above. Then retain the new font. // previous font to counter the retain above. Then retain the new font.
if (loadedFont != m_font) { if (loadedFont != m_font) {
...@@ -151,7 +133,6 @@ void FontPlatformData::setFont(NSFont *font) ...@@ -151,7 +133,6 @@ void FontPlatformData::setFont(NSFont *font)
CFRetain(loadedFont); CFRetain(loadedFont);
m_font = loadedFont; m_font = loadedFont;
} }
#endif
m_cgFont.adoptCF(cgFont); m_cgFont.adoptCF(cgFont);
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
...@@ -244,11 +225,6 @@ static CTFontDescriptorRef cascadeToLastResortAndDisableSwashesFontDescriptor() ...@@ -244,11 +225,6 @@ static CTFontDescriptorRef cascadeToLastResortAndDisableSwashesFontDescriptor()
return descriptor; return descriptor;
} }
String FontPlatformData::fontFamilyName() const
{
return String(CTFontCopyDisplayName(ctFont()));
}
CTFontRef FontPlatformData::ctFont() const CTFontRef FontPlatformData::ctFont() const
{ {
if (m_CTFont) if (m_CTFont)
...@@ -288,16 +264,7 @@ CTFontRef FontPlatformData::ctFont() const ...@@ -288,16 +264,7 @@ CTFontRef FontPlatformData::ctFont() const
return m_CTFont.get(); return m_CTFont.get();
} }
SkTypeface* FontPlatformData::typeface() const { bool FontPlatformData::isAATFont(CTFontRef ctFont) const
if (m_typeface)
return m_typeface.get();
m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont()));
return m_typeface.get();
}
#if OS(MACOSX)
static bool isAATFont(CTFontRef ctFont)
{ {
CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0); CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0);
if (table) { if (table) {
...@@ -311,21 +278,5 @@ static bool isAATFont(CTFontRef ctFont) ...@@ -311,21 +278,5 @@ static bool isAATFont(CTFontRef ctFont)
} }
return false; return false;
} }
#endif
HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{
CTFontRef font = ctFont();
// HarfBuzz can't handle AAT font
if (isAATFont(font))
return 0;
if (!m_harfBuzzFace) {
uint64_t uniqueID = reinterpret_cast<uintptr_t>(font);
m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this), uniqueID);
}
return m_harfBuzzFace.get();
}
} // namespace blink } // namespace blink
/*
* Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "platform/fonts/FontPlatformData.h"
#include "SkTypeface.h"
#include "platform/fonts/harfbuzz/HarfBuzzFace.h"
#include "wtf/text/WTFString.h"
namespace blink {
FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
: m_textSize(0)
, m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal)
, m_isHashTableDeletedValue(true)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(false)
#endif
{
}
FontPlatformData::FontPlatformData()
: m_textSize(0)
, m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal)
, m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(false)
#endif
{
}
FontPlatformData::FontPlatformData(float textSize, bool syntheticBold, bool syntheticItalic)
: m_textSize(textSize)
, m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(Horizontal)
, m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(false)
#endif
{
}
FontPlatformData::FontPlatformData(const FontPlatformData& src)
: m_typeface(src.m_typeface)
#if !OS(WIN)
, m_family(src.m_family)
#endif
, m_textSize(src.m_textSize)
, m_syntheticBold(src.m_syntheticBold)
, m_syntheticItalic(src.m_syntheticItalic)
, m_orientation(src.m_orientation)
, m_style(src.m_style)
, m_harfBuzzFace(nullptr)
, m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(src.m_paintTextFlags)
, m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
, m_minSizeForSubpixel(src.m_minSizeForSubpixel)
, m_useSubpixelPositioning(src.m_useSubpixelPositioning)
#endif
{
}
FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, bool subpixelTextPosition)
: m_typeface(tf)
#if !OS(WIN)
, m_family(family)
#endif
, m_textSize(textSize)
, m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation)
, m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(0)
, m_minSizeForAntiAlias(0)
, m_minSizeForSubpixel(0)
, m_useSubpixelPositioning(subpixelTextPosition)
#endif
{
querySystemForRenderStyle(subpixelTextPosition);
}
FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
: m_typeface(src.m_typeface)
#if !OS(WIN)
, m_family(src.m_family)
#endif
, m_textSize(textSize)
, m_syntheticBold(src.m_syntheticBold)
, m_syntheticItalic(src.m_syntheticItalic)
, m_orientation(src.m_orientation)
, m_harfBuzzFace(nullptr)
, m_isHashTableDeletedValue(false)
#if OS(WIN)
, m_paintTextFlags(src.m_paintTextFlags)
, m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
, m_minSizeForSubpixel(src.m_minSizeForSubpixel)
, m_useSubpixelPositioning(src.m_useSubpixelPositioning)
#endif
{
querySystemForRenderStyle(FontDescription::subpixelPositioning());
}
FontPlatformData::~FontPlatformData()
{
}
const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
{
m_typeface = src.m_typeface;
#if !OS(WIN)
m_family = src.m_family;
#endif
m_textSize = src.m_textSize;
m_syntheticBold = src.m_syntheticBold;
m_syntheticItalic = src.m_syntheticItalic;
m_harfBuzzFace = nullptr;
m_orientation = src.m_orientation;
m_style = src.m_style;
#if OS(WIN)
m_paintTextFlags = 0;
m_minSizeForAntiAlias = src.m_minSizeForAntiAlias;
m_minSizeForSubpixel = src.m_minSizeForSubpixel;
m_useSubpixelPositioning = src.m_useSubpixelPositioning;
#endif
return *this;
}
SkFontID FontPlatformData::uniqueID() const
{
return m_typeface->uniqueID();
}
String FontPlatformData::fontFamilyName() const
{
// FIXME(crbug.com/326582): come up with a proper way of handling SVG.
if (!this->typeface())
return "";
SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createFamilyNameIterator();
SkTypeface::LocalizedString localizedString;
while (fontFamilyIterator->next(&localizedString) && !localizedString.fString.size()) { }
fontFamilyIterator->unref();
return String(localizedString.fString.c_str());
}
bool FontPlatformData::operator==(const FontPlatformData& a) const
{
// If either of the typeface pointers are null then we test for pointer
// equality. Otherwise, we call SkTypeface::Equal on the valid pointers.
bool typefacesEqual;
if (!m_typeface || !a.m_typeface)
typefacesEqual = m_typeface == a.m_typeface;
else
typefacesEqual = SkTypeface::Equal(m_typeface.get(), a.m_typeface.get());
return typefacesEqual
&& m_textSize == a.m_textSize
&& m_syntheticBold == a.m_syntheticBold
&& m_syntheticItalic == a.m_syntheticItalic
&& m_orientation == a.m_orientation
&& m_style == a.m_style
&& m_isHashTableDeletedValue == a.m_isHashTableDeletedValue;
}
bool FontPlatformData::isFixedPitch() const
{
return typeface() && typeface()->isFixedPitch();
}
SkTypeface* FontPlatformData::typeface() const
{
return m_typeface.get();
}
HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{
if (!m_harfBuzzFace)
m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this), uniqueID());
return m_harfBuzzFace.get();
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment