Merge FontPlatformDataHarfBuzz and FontPlatformData headers

Those two files were split apart and redundantly copied
for non-Mac and Mac platforms. This is an attempt an unifying
them, as a preparation for removing the CoreText shaper.
We can merge the implementations in FontPlatformDataHarfBuzz.cpp
and FontPlatformData.cpp as a next step.

This is a reland after the original change 72f392cc147764ec75e4f
got reverted in bcfdb1312a26b0e611. Fix is to
change to the previous operator== implementation and add
m_isHashTableDeletedValue to the hash computation. 

I believe this addresses the observed crash issue as well.

BUG=334269, 411287
R=eae,arv

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

git-svn-id: svn://svn.chromium.org/blink/trunk@181541 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 9b4d2a52
...@@ -388,7 +388,6 @@ ...@@ -388,7 +388,6 @@
'fonts/cocoa/FontPlatformDataCocoa.mm', 'fonts/cocoa/FontPlatformDataCocoa.mm',
'fonts/harfbuzz/FontHarfBuzz.cpp', 'fonts/harfbuzz/FontHarfBuzz.cpp',
'fonts/harfbuzz/FontPlatformDataHarfBuzz.cpp', 'fonts/harfbuzz/FontPlatformDataHarfBuzz.cpp',
'fonts/harfbuzz/FontPlatformDataHarfBuzz.h',
'fonts/harfbuzz/HarfBuzzFace.cpp', 'fonts/harfbuzz/HarfBuzzFace.cpp',
'fonts/harfbuzz/HarfBuzzFace.h', 'fonts/harfbuzz/HarfBuzzFace.h',
'fonts/harfbuzz/HarfBuzzFaceCoreText.cpp', 'fonts/harfbuzz/HarfBuzzFaceCoreText.cpp',
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "config.h" #include "config.h"
#include "platform/fonts/FontPlatformData.h" #include "platform/fonts/FontPlatformData.h"
#include "SkTypeface.h"
#include "platform/fonts/harfbuzz/HarfBuzzFace.h"
#include "wtf/HashMap.h" #include "wtf/HashMap.h"
#include "wtf/text/StringHash.h" #include "wtf/text/StringHash.h"
#include "wtf/text/WTFString.h" #include "wtf/text/WTFString.h"
...@@ -29,73 +31,80 @@ ...@@ -29,73 +31,80 @@
#include "platform/fonts/harfbuzz/HarfBuzzFace.h" #include "platform/fonts/harfbuzz/HarfBuzzFace.h"
#endif #endif
using namespace std;
namespace blink { namespace blink {
FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
: m_syntheticBold(false) : m_textSize(0)
, m_syntheticOblique(false) , m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal) , m_orientation(Horizontal)
, m_size(0) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(RegularWidth) , m_widthVariant(RegularWidth)
#if OS(MACOSX) #if OS(MACOSX)
, m_font(hashTableDeletedFontValue()) , m_font(nullptr)
#endif #endif
, m_isColorBitmapFont(false) , m_isHashTableDeletedValue(true)
, m_isCompositeFontReference(false)
{ {
} }
FontPlatformData::FontPlatformData() FontPlatformData::FontPlatformData()
: m_syntheticBold(false) : m_textSize(0)
, m_syntheticOblique(false) , m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal) , m_orientation(Horizontal)
, m_size(0) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(RegularWidth) , m_widthVariant(RegularWidth)
#if OS(MACOSX) #if OS(MACOSX)
, m_font(0) , m_font(nullptr)
#endif #endif
, m_isColorBitmapFont(false) , m_isHashTableDeletedValue(false)
, m_isCompositeFontReference(false)
{ {
} }
FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant) FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_syntheticBold(syntheticBold) : m_textSize(size)
, m_syntheticOblique(syntheticOblique) , m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation) , m_orientation(orientation)
, m_size(size) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(widthVariant) , m_widthVariant(widthVariant)
#if OS(MACOSX) #if OS(MACOSX)
, m_font(0) , m_font(nullptr)
#endif #endif
, m_isColorBitmapFont(false) , m_isHashTableDeletedValue(false)
, m_isCompositeFontReference(false)
{ {
} }
#if OS(MACOSX) #if OS(MACOSX)
FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant) FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_syntheticBold(syntheticBold) : m_textSize(size)
, m_syntheticOblique(syntheticOblique) , m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation) , m_orientation(orientation)
, m_size(size)
, m_widthVariant(widthVariant)
, m_font(0)
, m_cgFont(cgFont)
, m_isColorBitmapFont(false) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false) , m_isCompositeFontReference(false)
, m_widthVariant(widthVariant)
, m_font(nullptr)
, m_cgFont(cgFont)
, m_isHashTableDeletedValue(false)
{ {
} }
#endif #endif
FontPlatformData::FontPlatformData(const FontPlatformData& source) FontPlatformData::FontPlatformData(const FontPlatformData& source)
: m_syntheticBold(source.m_syntheticBold) : m_textSize(source.m_textSize)
, m_syntheticOblique(source.m_syntheticOblique) , m_syntheticBold(source.m_syntheticBold)
, m_syntheticItalic(source.m_syntheticItalic)
, m_orientation(source.m_orientation) , m_orientation(source.m_orientation)
, m_size(source.m_size)
, m_widthVariant(source.m_widthVariant)
, m_isColorBitmapFont(source.m_isColorBitmapFont) , m_isColorBitmapFont(source.m_isColorBitmapFont)
, m_isCompositeFontReference(source.m_isCompositeFontReference) , m_isCompositeFontReference(source.m_isCompositeFontReference)
, m_widthVariant(source.m_widthVariant)
, m_isHashTableDeletedValue(false)
{ {
platformDataInit(source); platformDataInit(source);
} }
...@@ -107,9 +116,9 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe ...@@ -107,9 +116,9 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
return *this; return *this;
m_syntheticBold = other.m_syntheticBold; m_syntheticBold = other.m_syntheticBold;
m_syntheticOblique = other.m_syntheticOblique; m_syntheticItalic = other.m_syntheticItalic;
m_orientation = other.m_orientation; m_orientation = other.m_orientation;
m_size = other.m_size; m_textSize = other.m_textSize;
m_widthVariant = other.m_widthVariant; m_widthVariant = other.m_widthVariant;
m_isColorBitmapFont = other.m_isColorBitmapFont; m_isColorBitmapFont = other.m_isColorBitmapFont;
m_isCompositeFontReference = other.m_isCompositeFontReference; m_isCompositeFontReference = other.m_isCompositeFontReference;
...@@ -117,4 +126,22 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe ...@@ -117,4 +126,22 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
return platformDataAssign(other); return platformDataAssign(other);
} }
bool FontPlatformData::operator==(const FontPlatformData& a) const
{
return platformIsEqual(a)
&& m_textSize == a.m_textSize
&& m_isHashTableDeletedValue == a.m_isHashTableDeletedValue
&& m_syntheticBold == a.m_syntheticBold
&& m_syntheticItalic == a.m_syntheticItalic
&& m_orientation == a.m_orientation
#if !OS(MACOSX)
&& m_style == a.m_style
#endif
&& m_isColorBitmapFont == a.m_isColorBitmapFont
&& m_isCompositeFontReference == a.m_isCompositeFontReference
&& m_widthVariant == a.m_widthVariant;
}
} // namespace blink } // namespace blink
/* /*
* Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
* Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2007 Pioneer Research Center USA, Inc.
* Copyright (C) 2010, 2011 Brent Fulgham <bfulgham@webkit.org>
* *
* This library is free software; you can redistribute it and/or * Redistribution and use in source and binary forms, with or without
* modify it under the terms of the GNU Library General Public * modification, are permitted provided that the following conditions are
* License as published by the Free Software Foundation; either * met:
* version 2 of the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * * Redistributions of source code must retain the above copyright
* but WITHOUT ANY WARRANTY; without even the implied warranty of * notice, this list of conditions and the following disclaimer.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Redistributions in binary form must reproduce the above
* Library General Public License for more details. * copyright notice, this list of conditions and the following disclaimer
* * in the documentation and/or other materials provided with the
* You should have received a copy of the GNU Library General Public License * distribution.
* along with this library; see the file COPYING.LIB. If not, write to * * Neither the name of Google Inc. nor the names of its
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * contributors may be used to endorse or promote products derived from
* Boston, MA 02110-1301, USA. * 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.
*/ */
// FIXME: This is temporary until mac switch to using FontPlatformDataHarfBuzz.h and we merge it with this file.
#if !OS(MACOSX)
#include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h"
#else
#ifndef FontPlatformData_h #ifndef FontPlatformData_h
#define FontPlatformData_h #define FontPlatformData_h
#include "SkPaint.h"
#include "platform/PlatformExport.h" #include "platform/PlatformExport.h"
#include "platform/SharedBuffer.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontOrientation.h" #include "platform/fonts/FontOrientation.h"
#include "platform/fonts/FontWidthVariant.h" #include "platform/fonts/FontRenderStyle.h"
#include "platform/fonts/opentype/OpenTypeVerticalData.h"
#include "wtf/Forward.h"
#include "wtf/HashTableDeletedValueType.h"
#include "wtf/RefPtr.h"
#include "wtf/text/CString.h"
#include "wtf/text/StringImpl.h"
#if OS(MACOSX)
OBJC_CLASS NSFont; OBJC_CLASS NSFont;
typedef struct CGFont* CGFontRef; typedef struct CGFont* CGFontRef;
typedef const struct __CTFont* CTFontRef; typedef const struct __CTFont* CTFontRef;
#include "platform/fonts/mac/MemoryActivatedFont.h"
#include <CoreFoundation/CFBase.h> #include <CoreFoundation/CFBase.h>
#include <objc/objc-auto.h> #include <objc/objc-auto.h>
#include "wtf/Forward.h" inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
#include "wtf/HashTableDeletedValueType.h" #endif // OS(MACOSX)
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RetainPtr.h"
#include "wtf/text/StringImpl.h"
#include "platform/fonts/mac/MemoryActivatedFont.h"
#include "third_party/skia/include/core/SkTypeface.h"
typedef struct CGFont* CGFontRef; class SkTypeface;
typedef const struct __CTFont* CTFontRef; typedef uint32_t SkFontID;
typedef UInt32 FMFont;
typedef FMFont ATSUFontID;
typedef UInt32 ATSFontRef;
namespace blink { namespace blink {
class GraphicsContext;
class HarfBuzzFace; class HarfBuzzFace;
inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
class PLATFORM_EXPORT FontPlatformData { class PLATFORM_EXPORT FontPlatformData {
public: public:
// Used for deleted values in the font cache's hash tables. The hash table
// will create us with this structure, and it will compare other values
// to this "Deleted" one. It expects the Deleted one to be differentiable
// from the 0 one (created with the empty constructor), so we can't just
// set everything to 0.
FontPlatformData(WTF::HashTableDeletedValueType); FontPlatformData(WTF::HashTableDeletedValueType);
FontPlatformData(); FontPlatformData();
FontPlatformData(const FontPlatformData&); FontPlatformData(const FontPlatformData&);
FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth); #if OS(MACOSX)
FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticOblique = false, FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
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
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(const FontPlatformData& src, float textSize);
#endif
~FontPlatformData(); ~FontPlatformData();
#if OS(MACOSX)
NSFont* font() const { return m_font; } NSFont* font() const { return m_font; }
void setFont(NSFont*); void setFont(NSFont*);
CGFontRef cgFont() const { return m_cgFont.get(); } CGFontRef cgFont() const { return m_cgFont.get(); }
CTFontRef ctFont() const; CTFontRef ctFont() const;
SkTypeface* typeface() const;
bool roundsGlyphAdvances() const; bool roundsGlyphAdvances() const;
bool allowsLigatures() const; bool allowsLigatures() const;
String fontFamilyName() const;
bool isFixedPitch() const;
float size() const { return m_size; }
void setSize(float size) { m_size = size; }
bool syntheticBold() const { return m_syntheticBold; }
bool syntheticOblique() const { return m_syntheticOblique; }
bool isColorBitmapFont() const { return m_isColorBitmapFont; } bool isColorBitmapFont() const { return m_isColorBitmapFont; }
bool isCompositeFontReference() const { return m_isCompositeFontReference; } bool isCompositeFontReference() const { return m_isCompositeFontReference; }
FontOrientation orientation() const { return m_orientation; }
FontWidthVariant widthVariant() const { return m_widthVariant; } FontWidthVariant widthVariant() const { return m_widthVariant; }
#endif
void setOrientation(FontOrientation orientation) { m_orientation = orientation; } String fontFamilyName() const;
float size() const { return m_textSize; }
HarfBuzzFace* harfBuzzFace(); bool isFixedPitch() const;
bool syntheticBold() const { return m_syntheticBold; }
bool syntheticItalic() const { return m_syntheticItalic; }
unsigned hash() const SkTypeface* typeface() const;
{ HarfBuzzFace* harfBuzzFace() const;
ASSERT(m_font || !m_cgFont); SkFontID uniqueID() const;
uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<uintptr_t>(m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) }; unsigned hash() const;
return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
}
FontOrientation orientation() const { return m_orientation; }
void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold; }
void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheticItalic; }
bool operator==(const FontPlatformData&) const;
const FontPlatformData& operator=(const FontPlatformData&); const FontPlatformData& operator=(const FontPlatformData&);
bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; }
bool operator==(const FontPlatformData& other) const #if OS(WIN)
void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; }
unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; }
void setHinting(SkPaint::Hinting style)
{ {
return platformIsEqual(other) m_style.useAutoHint = 0;
&& m_size == other.m_size m_style.hintStyle = style;
&& m_syntheticBold == other.m_syntheticBold
&& m_syntheticOblique == other.m_syntheticOblique
&& m_isColorBitmapFont == other.m_isColorBitmapFont
&& m_isCompositeFontReference == other.m_isCompositeFontReference
&& m_orientation == other.m_orientation
&& m_widthVariant == other.m_widthVariant;
} }
#endif
bool fontContainsCharacter(UChar32 character);
bool isHashTableDeletedValue() const #if ENABLE(OPENTYPE_VERTICAL)
{ PassRefPtr<OpenTypeVerticalData> verticalData() const;
return m_font == hashTableDeletedFontValue(); PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
} #endif
#ifndef NDEBUG #ifndef NDEBUG
String description() const; String description() const;
#endif #endif
#if !OS(MACOSX)
// The returned styles are all actual styles without FontRenderStyle::NoPreference.
const FontRenderStyle& fontRenderStyle() const { return m_style; }
void setupPaint(SkPaint*, GraphicsContext* = 0) const;
#endif
#if OS(WIN)
int paintTextFlags() const { return m_paintTextFlags; }
#else
static void setHinting(SkPaint::Hinting);
static void setAutoHint(bool);
static void setUseBitmaps(bool);
static void setAntiAlias(bool);
static void setSubpixelRendering(bool);
#endif
private: private:
bool platformIsEqual(const FontPlatformData&) const; #if !OS(MACOSX)
void platformDataInit(const FontPlatformData&); bool static defaultUseSubpixelPositioning();
const FontPlatformData& platformDataAssign(const FontPlatformData&); void querySystemForRenderStyle(bool useSkiaSubpixelPositioning);
#if OS(MACOSX) #else
// Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters: // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
// Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same
// font as |nsFont|. This because the sandbox may block loading of the original font. // font as |nsFont|. This because the sandbox may block loading of the original font.
...@@ -145,31 +169,46 @@ private: ...@@ -145,31 +169,46 @@ 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&);
static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); }
bool platformIsEqual(const FontPlatformData&) const;
void platformDataInit(const FontPlatformData&);
const FontPlatformData& platformDataAssign(const FontPlatformData&);
#endif
mutable RefPtr<SkTypeface> m_typeface;
#if !OS(WIN)
CString m_family;
#endif #endif
public: public:
float m_textSize;
bool m_syntheticBold; bool m_syntheticBold;
bool m_syntheticOblique; bool m_syntheticItalic;
FontOrientation m_orientation; FontOrientation m_orientation;
float m_size; #if OS(MACOSX)
bool m_isColorBitmapFont;
bool m_isCompositeFontReference;
FontWidthVariant m_widthVariant; FontWidthVariant m_widthVariant;
#endif
private: private:
#if OS(MACOSX)
NSFont* m_font; NSFont* m_font;
RetainPtr<CGFontRef> m_cgFont; RetainPtr<CGFontRef> m_cgFont;
mutable RetainPtr<CTFontRef> m_CTFont; mutable RetainPtr<CTFontRef> m_CTFont;
RefPtr<MemoryActivatedFont> m_inMemoryFont; RefPtr<MemoryActivatedFont> m_inMemoryFont;
RefPtr<HarfBuzzFace> m_harfBuzzFace; #else
mutable RefPtr<SkTypeface> m_typeface; FontRenderStyle m_style;
#endif
bool m_isColorBitmapFont; mutable RefPtr<HarfBuzzFace> m_harfBuzzFace;
bool m_isCompositeFontReference; bool m_isHashTableDeletedValue;
#if OS(WIN)
int m_paintTextFlags;
bool m_useSubpixelPositioning;
unsigned m_minSizeForAntiAlias;
#endif
}; };
} // namespace blink } // namespace blink
#endif // FontPlatformData_h #endif // ifdef FontPlatformData_h
#endif
...@@ -35,18 +35,26 @@ ...@@ -35,18 +35,26 @@
namespace blink { namespace blink {
unsigned FontPlatformData::hash() const
{
ASSERT(m_font || !m_cgFont);
uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<uintptr_t>(m_isHashTableDeletedValue << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticItalic) };
return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
}
// These CoreText Text Spacing feature selectors are not defined in CoreText. // These CoreText Text Spacing feature selectors are not defined in CoreText.
enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidth, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidth, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth };
FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant) FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_syntheticBold(syntheticBold) : m_textSize(size)
, m_syntheticOblique(syntheticOblique) , m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation) , m_orientation(orientation)
, m_size(size)
, m_widthVariant(widthVariant)
, m_font(nsFont)
, m_isColorBitmapFont(false) , m_isColorBitmapFont(false)
, m_isCompositeFontReference(false) , m_isCompositeFontReference(false)
, m_widthVariant(widthVariant)
, m_font(nsFont)
, m_isHashTableDeletedValue(false)
{ {
ASSERT_ARG(nsFont, nsFont); ASSERT_ARG(nsFont, nsFont);
...@@ -129,11 +137,11 @@ void FontPlatformData::setFont(NSFont *font) ...@@ -129,11 +137,11 @@ void FontPlatformData::setFont(NSFont *font)
if (m_font) if (m_font)
CFRelease(m_font); CFRelease(m_font);
m_font = font; m_font = font;
m_size = [font pointSize]; m_textSize = [font pointSize];
CGFontRef cgFont = 0; CGFontRef cgFont = 0;
NSFont* loadedFont = 0; NSFont* loadedFont = 0;
loadFont(m_font, m_size, loadedFont, cgFont); loadFont(m_font, m_textSize, loadedFont, cgFont);
#if OS(MACOSX) #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
...@@ -247,7 +255,7 @@ CTFontRef FontPlatformData::ctFont() const ...@@ -247,7 +255,7 @@ CTFontRef FontPlatformData::ctFont() const
return m_CTFont.get(); return m_CTFont.get();
if (m_inMemoryFont) { if (m_inMemoryFont) {
m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(), m_size, 0, cascadeToLastResortFontDescriptor())); m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(), m_textSize, 0, cascadeToLastResortFontDescriptor()));
return m_CTFont.get(); return m_CTFont.get();
} }
...@@ -260,9 +268,9 @@ CTFontRef FontPlatformData::ctFont() const ...@@ -260,9 +268,9 @@ CTFontRef FontPlatformData::ctFont() const
fontDescriptor = cascadeToLastResortAndDisableSwashesFontDescriptor(); fontDescriptor = cascadeToLastResortAndDisableSwashesFontDescriptor();
else else
fontDescriptor = cascadeToLastResortFontDescriptor(); fontDescriptor = cascadeToLastResortFontDescriptor();
m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_size, 0, fontDescriptor)); m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_textSize, 0, fontDescriptor));
} else } else
m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, cascadeToLastResortFontDescriptor())); m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_textSize, 0, cascadeToLastResortFontDescriptor()));
if (m_widthVariant != RegularWidth) { if (m_widthVariant != RegularWidth) {
int featureTypeValue = kTextSpacingType; int featureTypeValue = kTextSpacingType;
...@@ -271,7 +279,7 @@ CTFontRef FontPlatformData::ctFont() const ...@@ -271,7 +279,7 @@ CTFontRef FontPlatformData::ctFont() const
RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureTypeValue)); RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureTypeValue));
RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureSelectorValue)); RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureSelectorValue));
RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCreateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.get())); RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCreateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.get()));
RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(newDescriptor.get(), m_size, 0)); RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(newDescriptor.get(), m_textSize, 0));
if (newFont) if (newFont)
m_CTFont = newFont; m_CTFont = newFont;
...@@ -280,7 +288,7 @@ CTFontRef FontPlatformData::ctFont() const ...@@ -280,7 +288,7 @@ CTFontRef FontPlatformData::ctFont() const
return m_CTFont.get(); return m_CTFont.get();
} }
SkTypeface* FontPlatformData::typeface() const{ SkTypeface* FontPlatformData::typeface() const {
if (m_typeface) if (m_typeface)
return m_typeface.get(); return m_typeface.get();
...@@ -303,8 +311,9 @@ static bool isAATFont(CTFontRef ctFont) ...@@ -303,8 +311,9 @@ static bool isAATFont(CTFontRef ctFont)
} }
return false; return false;
} }
#endif
HarfBuzzFace* FontPlatformData::harfBuzzFace() HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{ {
CTFontRef font = ctFont(); CTFontRef font = ctFont();
// HarfBuzz can't handle AAT font // HarfBuzz can't handle AAT font
...@@ -317,14 +326,13 @@ HarfBuzzFace* FontPlatformData::harfBuzzFace() ...@@ -317,14 +326,13 @@ HarfBuzzFace* FontPlatformData::harfBuzzFace()
} }
return m_harfBuzzFace.get(); return m_harfBuzzFace.get();
} }
#endif
#ifndef NDEBUG #ifndef NDEBUG
String FontPlatformData::description() const String FontPlatformData::description() const
{ {
RetainPtr<CFStringRef> cgFontDescription(AdoptCF, CFCopyDescription(cgFont())); RetainPtr<CFStringRef> cgFontDescription(AdoptCF, CFCopyDescription(cgFont()));
return String(cgFontDescription.get()) + " " + String::number(m_size) return String(cgFontDescription.get()) + " " + String::number(m_textSize)
+ (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticOblique ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : ""); + (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticItalic ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : "");
} }
#endif #endif
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
*/ */
#include "config.h" #include "config.h"
#include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h" #include "platform/fonts/FontPlatformData.h"
#include "SkTypeface.h" #include "SkTypeface.h"
#include "platform/fonts/harfbuzz/HarfBuzzFace.h" #include "platform/fonts/harfbuzz/HarfBuzzFace.h"
...@@ -148,7 +148,7 @@ FontPlatformData::~FontPlatformData() ...@@ -148,7 +148,7 @@ FontPlatformData::~FontPlatformData()
{ {
} }
FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src) const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
{ {
m_typeface = src.m_typeface; m_typeface = src.m_typeface;
#if !OS(WIN) #if !OS(WIN)
...@@ -218,6 +218,11 @@ bool FontPlatformData::isFixedPitch() const ...@@ -218,6 +218,11 @@ bool FontPlatformData::isFixedPitch() const
return typeface() && typeface()->isFixedPitch(); return typeface() && typeface()->isFixedPitch();
} }
SkTypeface* FontPlatformData::typeface() const
{
return m_typeface.get();
}
HarfBuzzFace* FontPlatformData::harfBuzzFace() const HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{ {
if (!m_harfBuzzFace) if (!m_harfBuzzFace)
......
/*
* 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.
*/
#ifndef FontPlatformDataHarfBuzz_h
#define FontPlatformDataHarfBuzz_h
#include "SkPaint.h"
#include "platform/SharedBuffer.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontOrientation.h"
#include "platform/fonts/FontRenderStyle.h"
#include "platform/fonts/opentype/OpenTypeVerticalData.h"
#include "wtf/Forward.h"
#include "wtf/HashTableDeletedValueType.h"
#include "wtf/RefPtr.h"
#include "wtf/text/CString.h"
#include "wtf/text/StringImpl.h"
class SkTypeface;
typedef uint32_t SkFontID;
namespace blink {
class GraphicsContext;
class HarfBuzzFace;
class PLATFORM_EXPORT FontPlatformData {
public:
// Used for deleted values in the font cache's hash tables. The hash table
// will create us with this structure, and it will compare other values
// to this "Deleted" one. It expects the Deleted one to be differentiable
// from the 0 one (created with the empty constructor), so we can't just
// set everything to 0.
FontPlatformData(WTF::HashTableDeletedValueType);
FontPlatformData();
FontPlatformData(float textSize, bool syntheticBold, bool syntheticItalic);
FontPlatformData(const FontPlatformData&);
FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subpixelTextPosition = defaultUseSubpixelPositioning());
FontPlatformData(const FontPlatformData& src, float textSize);
~FontPlatformData();
String fontFamilyName() const;
float size() const { return m_textSize; }
bool isFixedPitch() const;
SkTypeface* typeface() const { return m_typeface.get(); }
HarfBuzzFace* harfBuzzFace() const;
SkFontID uniqueID() const;
unsigned hash() const;
FontOrientation orientation() const { return m_orientation; }
void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold; }
void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheticItalic; }
bool operator==(const FontPlatformData&) const;
FontPlatformData& operator=(const FontPlatformData&);
bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; }
#if OS(WIN)
void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; }
unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; }
void setMinSizeForSubpixel(float size) { m_minSizeForSubpixel = size; }
float minSizeForSubpixel() const { return m_minSizeForSubpixel; }
void setHinting(SkPaint::Hinting style)
{
m_style.useAutoHint = 0;
m_style.hintStyle = style;
}
#endif
bool fontContainsCharacter(UChar32 character);
#if ENABLE(OPENTYPE_VERTICAL)
PassRefPtr<OpenTypeVerticalData> verticalData() const;
PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
#endif
#ifndef NDEBUG
String description() const;
#endif
// The returned styles are all actual styles without FontRenderStyle::NoPreference.
const FontRenderStyle& fontRenderStyle() const { return m_style; }
void setupPaint(SkPaint*, GraphicsContext* = 0) const;
#if OS(WIN)
int paintTextFlags() const { return m_paintTextFlags; }
#else
static void setHinting(SkPaint::Hinting);
static void setAutoHint(bool);
static void setUseBitmaps(bool);
static void setAntiAlias(bool);
static void setSubpixelRendering(bool);
#endif
private:
bool static defaultUseSubpixelPositioning();
void querySystemForRenderStyle(bool useSkiaSubpixelPositioning);
RefPtr<SkTypeface> m_typeface;
#if !OS(WIN)
CString m_family;
#endif
float m_textSize;
bool m_syntheticBold;
bool m_syntheticItalic;
FontOrientation m_orientation;
FontRenderStyle m_style;
mutable RefPtr<HarfBuzzFace> m_harfBuzzFace;
bool m_isHashTableDeletedValue;
#if OS(WIN)
int m_paintTextFlags;
bool m_useSubpixelPositioning;
unsigned m_minSizeForAntiAlias;
float m_minSizeForSubpixel;
#endif
};
} // namespace blink
#endif // ifdef FontPlatformDataHarfBuzz_h
...@@ -133,7 +133,7 @@ hb_font_t* HarfBuzzFace::createFont() ...@@ -133,7 +133,7 @@ hb_font_t* HarfBuzzFace::createFont()
{ {
hb_font_t* font = hb_font_create(m_face); hb_font_t* font = hb_font_create(m_face);
hb_font_set_funcs(font, harfBuzzCoreTextGetFontFuncs(), m_platformData, 0); hb_font_set_funcs(font, harfBuzzCoreTextGetFontFuncs(), m_platformData, 0);
const float size = m_platformData->m_size; const float size = m_platformData->m_textSize;
hb_font_set_ppem(font, size, size); hb_font_set_ppem(font, size, size);
const int scale = (1 << 16) * static_cast<int>(size); const int scale = (1 << 16) * static_cast<int>(size);
hb_font_set_scale(font, scale, scale); hb_font_set_scale(font, scale, scale);
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "SkTypeface.h" #include "SkTypeface.h"
#include "platform/LayoutTestSupport.h" #include "platform/LayoutTestSupport.h"
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
#include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h" #include "platform/fonts/FontPlatformData.h"
#include "platform/graphics/GraphicsContext.h" #include "platform/graphics/GraphicsContext.h"
#include "public/platform/linux/WebFontRenderStyle.h" #include "public/platform/linux/WebFontRenderStyle.h"
#include "public/platform/linux/WebSandboxSupport.h" #include "public/platform/linux/WebSandboxSupport.h"
......
...@@ -149,7 +149,7 @@ PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip ...@@ -149,7 +149,7 @@ PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
traits = [fontManager traitsOfFont:nsFont]; traits = [fontManager traitsOfFont:nsFont];
if (platformData.m_syntheticBold) if (platformData.m_syntheticBold)
traits |= NSBoldFontMask; traits |= NSBoldFontMask;
if (platformData.m_syntheticOblique) if (platformData.m_syntheticItalic)
traits |= NSFontItalicTrait; traits |= NSFontItalicTrait;
weight = [fontManager weightOfFont:nsFont]; weight = [fontManager weightOfFont:nsFont];
size = [nsFont pointSize]; size = [nsFont pointSize];
...@@ -179,7 +179,7 @@ PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip ...@@ -179,7 +179,7 @@ PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
FontPlatformData alternateFont(substituteFont, platformData.size(), FontPlatformData alternateFont(substituteFont, platformData.size(),
isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFontWeight), isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFontWeight),
(traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTrait), (traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTrait),
platformData.m_orientation); platformData.orientation());
return fontDataFromFontPlatformData(&alternateFont, DoNotRetain); return fontDataFromFontPlatformData(&alternateFont, DoNotRetain);
} }
...@@ -220,11 +220,11 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD ...@@ -220,11 +220,11 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerFont]; NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerFont];
bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(actualWeight)) || fontDescription.isSyntheticBold(); bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(actualWeight)) || fontDescription.isSyntheticBold();
bool syntheticOblique = ((traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait)) || fontDescription.isSyntheticItalic(); bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait)) || fontDescription.isSyntheticItalic();
// FontPlatformData::font() can be null for the case of Chromium out-of-process font loading. // FontPlatformData::font() can be null for the case of Chromium out-of-process font loading.
// In that case, we don't want to use the platformData. // In that case, we don't want to use the platformData.
OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platformFont, size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant())); OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platformFont, size, syntheticBold, syntheticItalic, fontDescription.orientation(), fontDescription.widthVariant()));
if (!platformData->font()) if (!platformData->font())
return 0; return 0;
return platformData.leakPtr(); return platformData.leakPtr();
......
...@@ -52,7 +52,7 @@ bool FontPlatformFeatures::canExpandAroundIdeographsInComplexText() ...@@ -52,7 +52,7 @@ bool FontPlatformFeatures::canExpandAroundIdeographsInComplexText()
static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Font* font, bool shouldAntialias, bool shouldSmoothFonts) static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Font* font, bool shouldAntialias, bool shouldSmoothFonts)
{ {
const FontPlatformData& platformData = fontData->platformData(); const FontPlatformData& platformData = fontData->platformData();
const float textSize = platformData.m_size >= 0 ? platformData.m_size : 12; const float textSize = platformData.m_textSize >= 0 ? platformData.m_textSize : 12;
paint->setAntiAlias(shouldAntialias); paint->setAntiAlias(shouldAntialias);
paint->setEmbeddedBitmapText(false); paint->setEmbeddedBitmapText(false);
...@@ -60,7 +60,7 @@ static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Fon ...@@ -60,7 +60,7 @@ static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Fon
paint->setVerticalText(platformData.orientation() == Vertical); paint->setVerticalText(platformData.orientation() == Vertical);
paint->setTypeface(platformData.typeface()); paint->setTypeface(platformData.typeface());
paint->setFakeBoldText(platformData.m_syntheticBold); paint->setFakeBoldText(platformData.m_syntheticBold);
paint->setTextSkewX(platformData.m_syntheticOblique ? -SK_Scalar1 / 4 : 0); paint->setTextSkewX(platformData.m_syntheticItalic ? -SK_Scalar1 / 4 : 0);
paint->setAutohinted(false); // freetype specific paint->setAutohinted(false); // freetype specific
paint->setLCDRenderText(shouldSmoothFonts); paint->setLCDRenderText(shouldSmoothFonts);
paint->setSubpixelText(true); paint->setSubpixelText(true);
......
...@@ -131,9 +131,9 @@ const SimpleFontData* SimpleFontData::getCompositeFontReferenceFontData(NSFont * ...@@ -131,9 +131,9 @@ const SimpleFontData* SimpleFontData::getCompositeFontReferenceFontData(NSFont *
CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(substituteFont)); CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(substituteFont));
bool syntheticBold = platformData().syntheticBold() && !(traits & kCTFontBoldTrait); bool syntheticBold = platformData().syntheticBold() && !(traits & kCTFontBoldTrait);
bool syntheticOblique = platformData().syntheticOblique() && !(traits & kCTFontItalicTrait); bool syntheticItalic = platformData().syntheticItalic() && !(traits & kCTFontItalicTrait);
FontPlatformData substitutePlatform(substituteFont, platformData().size(), syntheticBold, syntheticOblique, platformData().orientation(), platformData().widthVariant()); FontPlatformData substitutePlatform(substituteFont, platformData().size(), syntheticBold, syntheticItalic, platformData().orientation(), platformData().widthVariant());
SimpleFontData* value = new SimpleFontData(substitutePlatform, isCustomFont() ? CustomFontData::create() : nullptr); SimpleFontData* value = new SimpleFontData(substitutePlatform, isCustomFont() ? CustomFontData::create() : nullptr);
if (value) { if (value) {
CFDictionaryAddValue(dictionary, key, value); CFDictionaryAddValue(dictionary, key, value);
...@@ -215,7 +215,7 @@ void SimpleFontData::platformInit() ...@@ -215,7 +215,7 @@ void SimpleFontData::platformInit()
iLineGap = CGFontGetLeading(m_platformData.cgFont()); iLineGap = CGFontGetLeading(m_platformData.cgFont());
unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont()); unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont());
float pointSize = m_platformData.m_size; float pointSize = m_platformData.m_textSize;
float ascent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize; float ascent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize;
float descent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize; float descent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize;
float lineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize; float lineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
...@@ -281,7 +281,7 @@ void SimpleFontData::platformCharWidthInit() ...@@ -281,7 +281,7 @@ void SimpleFontData::platformCharWidthInit()
if (os2Table && CFDataGetLength(os2Table.get()) >= 4) { if (os2Table && CFDataGetLength(os2Table.get()) >= 4) {
const UInt8* os2 = CFDataGetBytePtr(os2Table.get()); const UInt8* os2 = CFDataGetBytePtr(os2Table.get());
SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3]; SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3];
m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData.m_size; m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData.m_textSize;
} }
RetainPtr<CFDataRef> headTable(AdoptCF, copyFontTableForTag(m_platformData, 'head')); RetainPtr<CFDataRef> headTable(AdoptCF, copyFontTableForTag(m_platformData, 'head'));
...@@ -292,7 +292,7 @@ void SimpleFontData::platformCharWidthInit() ...@@ -292,7 +292,7 @@ void SimpleFontData::platformCharWidthInit()
SInt16 xMin = static_cast<SInt16>(uxMin); SInt16 xMin = static_cast<SInt16>(uxMin);
SInt16 xMax = static_cast<SInt16>(uxMax); SInt16 xMax = static_cast<SInt16>(uxMax);
float diff = static_cast<float>(xMax - xMin); float diff = static_cast<float>(xMax - xMin);
m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_platformData.m_size; m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_platformData.m_textSize;
} }
// Fallback to a cross-platform estimate, which will populate these values if they are non-positive. // Fallback to a cross-platform estimate, which will populate these values if they are non-positive.
...@@ -315,7 +315,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo ...@@ -315,7 +315,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo
{ {
if (isCustomFont()) { if (isCustomFont()) {
FontPlatformData scaledFontData(m_platformData); FontPlatformData scaledFontData(m_platformData);
scaledFontData.m_size = scaledFontData.m_size * scaleFactor; scaledFontData.m_textSize = scaledFontData.m_textSize * scaleFactor;
return SimpleFontData::create(scaledFontData, CustomFontData::create()); return SimpleFontData::create(scaledFontData, CustomFontData::create());
} }
...@@ -332,12 +332,12 @@ PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo ...@@ -332,12 +332,12 @@ PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo
if (m_platformData.m_syntheticBold) if (m_platformData.m_syntheticBold)
fontTraits |= NSBoldFontMask; fontTraits |= NSBoldFontMask;
if (m_platformData.m_syntheticOblique) if (m_platformData.m_syntheticItalic)
fontTraits |= NSItalicFontMask; fontTraits |= NSItalicFontMask;
NSFontTraitMask scaledFontTraits = [fontManager traitsOfFont:scaledFontData.font()]; NSFontTraitMask scaledFontTraits = [fontManager traitsOfFont:scaledFontData.font()];
scaledFontData.m_syntheticBold = (fontTraits & NSBoldFontMask) && !(scaledFontTraits & NSBoldFontMask); scaledFontData.m_syntheticBold = (fontTraits & NSBoldFontMask) && !(scaledFontTraits & NSBoldFontMask);
scaledFontData.m_syntheticOblique = (fontTraits & NSItalicFontMask) && !(scaledFontTraits & NSItalicFontMask); scaledFontData.m_syntheticItalic = (fontTraits & NSItalicFontMask) && !(scaledFontTraits & NSItalicFontMask);
// SimpleFontData::platformDestroy() takes care of not deleting the cached font data twice. // SimpleFontData::platformDestroy() takes care of not deleting the cached font data twice.
return FontCache::fontCache()->fontDataFromFontPlatformData(&scaledFontData); return FontCache::fontCache()->fontDataFromFontPlatformData(&scaledFontData);
...@@ -388,7 +388,7 @@ float SimpleFontData::platformWidthForGlyph(Glyph glyph) const ...@@ -388,7 +388,7 @@ float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
if (font && platformData().isColorBitmapFont()) if (font && platformData().isColorBitmapFont())
advance = NSSizeToCGSize([font advancementForGlyph:glyph]); advance = NSSizeToCGSize([font advancementForGlyph:glyph]);
else { else {
float pointSize = platformData().m_size; float pointSize = platformData().m_textSize;
CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize); CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, cgFontRenderingModeForNSFont(font), &glyph, 1, &advance)) { if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, cgFontRenderingModeForNSFont(font), &glyph, 1, &advance)) {
WTF_LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displayName], pointSize); WTF_LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displayName], pointSize);
......
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
#include "platform/fonts/FontDescription.h" #include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontFaceCreationParams.h" #include "platform/fonts/FontFaceCreationParams.h"
#include "platform/fonts/FontPlatformData.h"
#include "platform/fonts/SimpleFontData.h" #include "platform/fonts/SimpleFontData.h"
#include "platform/fonts/harfbuzz/FontPlatformDataHarfbuzz.h"
#include "platform/fonts/win/FontFallbackWin.h" #include "platform/fonts/win/FontFallbackWin.h"
namespace blink { namespace blink {
......
...@@ -189,7 +189,7 @@ static BOOL betterChoice(NSFontTraitMask desiredTraits, int desiredWeight, ...@@ -189,7 +189,7 @@ static BOOL betterChoice(NSFontTraitMask desiredTraits, int desiredWeight,
int actualWeight = [fontManager weightOfFont:font]; int actualWeight = [fontManager weightOfFont:font];
bool syntheticBold = desiredWeight >= 7 && actualWeight < 7; bool syntheticBold = desiredWeight >= 7 && actualWeight < 7;
bool syntheticOblique = (desiredTraits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait); bool syntheticItalic = (desiredTraits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
// There are some malformed fonts that will be correctly returned by -fontWithFamily:traits:weight:size: as a match for a particular trait, // There are some malformed fonts that will be correctly returned by -fontWithFamily:traits:weight:size: as a match for a particular trait,
// though -[NSFontManager traitsOfFont:] incorrectly claims the font does not have the specified trait. This could result in applying // though -[NSFontManager traitsOfFont:] incorrectly claims the font does not have the specified trait. This could result in applying
...@@ -201,7 +201,7 @@ static BOOL betterChoice(NSFontTraitMask desiredTraits, int desiredWeight, ...@@ -201,7 +201,7 @@ static BOOL betterChoice(NSFontTraitMask desiredTraits, int desiredWeight,
if (syntheticBold) if (syntheticBold)
nonSyntheticTraits &= ~NSBoldFontMask; nonSyntheticTraits &= ~NSBoldFontMask;
if (syntheticOblique) if (syntheticItalic)
nonSyntheticTraits &= ~NSItalicFontMask; nonSyntheticTraits &= ~NSItalicFontMask;
if (nonSyntheticTraits != desiredTraits) { if (nonSyntheticTraits != desiredTraits) {
......
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