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 @@
'fonts/cocoa/FontPlatformDataCocoa.mm',
'fonts/harfbuzz/FontHarfBuzz.cpp',
'fonts/harfbuzz/FontPlatformDataHarfBuzz.cpp',
'fonts/harfbuzz/FontPlatformDataHarfBuzz.h',
'fonts/harfbuzz/HarfBuzzFace.cpp',
'fonts/harfbuzz/HarfBuzzFace.h',
'fonts/harfbuzz/HarfBuzzFaceCoreText.cpp',
......
......@@ -21,6 +21,8 @@
#include "config.h"
#include "platform/fonts/FontPlatformData.h"
#include "SkTypeface.h"
#include "platform/fonts/harfbuzz/HarfBuzzFace.h"
#include "wtf/HashMap.h"
#include "wtf/text/StringHash.h"
#include "wtf/text/WTFString.h"
......@@ -29,73 +31,80 @@
#include "platform/fonts/harfbuzz/HarfBuzzFace.h"
#endif
using namespace std;
namespace blink {
FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
: m_syntheticBold(false)
, m_syntheticOblique(false)
: m_textSize(0)
, m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal)
, m_size(0)
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(RegularWidth)
#if OS(MACOSX)
, m_font(hashTableDeletedFontValue())
, m_font(nullptr)
#endif
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_isHashTableDeletedValue(true)
{
}
FontPlatformData::FontPlatformData()
: m_syntheticBold(false)
, m_syntheticOblique(false)
: m_textSize(0)
, m_syntheticBold(false)
, m_syntheticItalic(false)
, m_orientation(Horizontal)
, m_size(0)
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(RegularWidth)
#if OS(MACOSX)
, m_font(0)
, m_font(nullptr)
#endif
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_isHashTableDeletedValue(false)
{
}
FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
: m_syntheticBold(syntheticBold)
, m_syntheticOblique(syntheticOblique)
FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_textSize(size)
, m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation)
, m_size(size)
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(widthVariant)
#if OS(MACOSX)
, m_font(0)
, m_font(nullptr)
#endif
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_isHashTableDeletedValue(false)
{
}
#if OS(MACOSX)
FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
: m_syntheticBold(syntheticBold)
, m_syntheticOblique(syntheticOblique)
FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_textSize(size)
, m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation)
, m_size(size)
, m_widthVariant(widthVariant)
, m_font(0)
, m_cgFont(cgFont)
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(widthVariant)
, m_font(nullptr)
, m_cgFont(cgFont)
, m_isHashTableDeletedValue(false)
{
}
#endif
FontPlatformData::FontPlatformData(const FontPlatformData& source)
: m_syntheticBold(source.m_syntheticBold)
, m_syntheticOblique(source.m_syntheticOblique)
: m_textSize(source.m_textSize)
, m_syntheticBold(source.m_syntheticBold)
, m_syntheticItalic(source.m_syntheticItalic)
, m_orientation(source.m_orientation)
, m_size(source.m_size)
, m_widthVariant(source.m_widthVariant)
, m_isColorBitmapFont(source.m_isColorBitmapFont)
, m_isCompositeFontReference(source.m_isCompositeFontReference)
, m_widthVariant(source.m_widthVariant)
, m_isHashTableDeletedValue(false)
{
platformDataInit(source);
}
......@@ -107,9 +116,9 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
return *this;
m_syntheticBold = other.m_syntheticBold;
m_syntheticOblique = other.m_syntheticOblique;
m_syntheticItalic = other.m_syntheticItalic;
m_orientation = other.m_orientation;
m_size = other.m_size;
m_textSize = other.m_textSize;
m_widthVariant = other.m_widthVariant;
m_isColorBitmapFont = other.m_isColorBitmapFont;
m_isCompositeFontReference = other.m_isCompositeFontReference;
......@@ -117,4 +126,22 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
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
/*
* Copyright (C) 2006, 2007, 2008, 2010 Apple Inc.
* 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>
* Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
* * 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.
*/
// 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
#define FontPlatformData_h
#include "SkPaint.h"
#include "platform/PlatformExport.h"
#include "platform/SharedBuffer.h"
#include "platform/fonts/FontDescription.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;
typedef struct CGFont* CGFontRef;
typedef const struct __CTFont* CTFontRef;
#include "platform/fonts/mac/MemoryActivatedFont.h"
#include <CoreFoundation/CFBase.h>
#include <objc/objc-auto.h>
#include "wtf/Forward.h"
#include "wtf/HashTableDeletedValueType.h"
#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"
inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
#endif // OS(MACOSX)
typedef struct CGFont* CGFontRef;
typedef const struct __CTFont* CTFontRef;
typedef UInt32 FMFont;
typedef FMFont ATSUFontID;
typedef UInt32 ATSFontRef;
class SkTypeface;
typedef uint32_t SkFontID;
namespace blink {
class GraphicsContext;
class HarfBuzzFace;
inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); }
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(const FontPlatformData&);
FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool syntheticOblique = false,
#if OS(MACOSX)
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);
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();
#if OS(MACOSX)
NSFont* font() const { return m_font; }
void setFont(NSFont*);
CGFontRef cgFont() const { return m_cgFont.get(); }
CTFontRef ctFont() const;
SkTypeface* typeface() const;
bool roundsGlyphAdvances() 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 isCompositeFontReference() const { return m_isCompositeFontReference; }
FontOrientation orientation() const { return m_orientation; }
FontWidthVariant widthVariant() const { return m_widthVariant; }
#endif
void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
HarfBuzzFace* harfBuzzFace();
String fontFamilyName() const;
float size() const { return m_textSize; }
bool isFixedPitch() const;
bool syntheticBold() const { return m_syntheticBold; }
bool syntheticItalic() const { return m_syntheticItalic; }
unsigned hash() const
{
ASSERT(m_font || !m_cgFont);
uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<uintptr_t>(m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) };
return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
}
SkTypeface* typeface() const;
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;
const FontPlatformData& operator=(const FontPlatformData&);
bool operator==(const FontPlatformData& other) const
bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; }
#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_size == other.m_size
&& 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;
m_style.useAutoHint = 0;
m_style.hintStyle = style;
}
#endif
bool fontContainsCharacter(UChar32 character);
bool isHashTableDeletedValue() const
{
return m_font == hashTableDeletedFontValue();
}
#if ENABLE(OPENTYPE_VERTICAL)
PassRefPtr<OpenTypeVerticalData> verticalData() const;
PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
#endif
#ifndef NDEBUG
String description() const;
#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:
bool platformIsEqual(const FontPlatformData&) const;
void platformDataInit(const FontPlatformData&);
const FontPlatformData& platformDataAssign(const FontPlatformData&);
#if OS(MACOSX)
#if !OS(MACOSX)
bool static defaultUseSubpixelPositioning();
void querySystemForRenderStyle(bool useSkiaSubpixelPositioning);
#else
// 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
// font as |nsFont|. This because the sandbox may block loading of the original font.
......@@ -145,31 +169,46 @@ private:
// 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.
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
public:
float m_textSize;
bool m_syntheticBold;
bool m_syntheticOblique;
bool m_syntheticItalic;
FontOrientation m_orientation;
float m_size;
#if OS(MACOSX)
bool m_isColorBitmapFont;
bool m_isCompositeFontReference;
FontWidthVariant m_widthVariant;
#endif
private:
#if OS(MACOSX)
NSFont* m_font;
RetainPtr<CGFontRef> m_cgFont;
mutable RetainPtr<CTFontRef> m_CTFont;
RefPtr<MemoryActivatedFont> m_inMemoryFont;
RefPtr<HarfBuzzFace> m_harfBuzzFace;
mutable RefPtr<SkTypeface> m_typeface;
#else
FontRenderStyle m_style;
#endif
bool m_isColorBitmapFont;
bool m_isCompositeFontReference;
mutable RefPtr<HarfBuzzFace> m_harfBuzzFace;
bool m_isHashTableDeletedValue;
#if OS(WIN)
int m_paintTextFlags;
bool m_useSubpixelPositioning;
unsigned m_minSizeForAntiAlias;
#endif
};
} // namespace blink
#endif // FontPlatformData_h
#endif
#endif // ifdef FontPlatformData_h
......@@ -35,18 +35,26 @@
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.
enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidth, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth };
FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
: m_syntheticBold(syntheticBold)
, m_syntheticOblique(syntheticOblique)
FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVariant)
: m_textSize(size)
, m_syntheticBold(syntheticBold)
, m_syntheticItalic(syntheticItalic)
, m_orientation(orientation)
, m_size(size)
, m_widthVariant(widthVariant)
, m_font(nsFont)
, m_isColorBitmapFont(false)
, m_isCompositeFontReference(false)
, m_widthVariant(widthVariant)
, m_font(nsFont)
, m_isHashTableDeletedValue(false)
{
ASSERT_ARG(nsFont, nsFont);
......@@ -129,11 +137,11 @@ void FontPlatformData::setFont(NSFont *font)
if (m_font)
CFRelease(m_font);
m_font = font;
m_size = [font pointSize];
m_textSize = [font pointSize];
CGFontRef cgFont = 0;
NSFont* loadedFont = 0;
loadFont(m_font, m_size, loadedFont, cgFont);
loadFont(m_font, m_textSize, loadedFont, cgFont);
#if OS(MACOSX)
// If loadFont replaced m_font with a fallback font, then release the
......@@ -247,7 +255,7 @@ CTFontRef FontPlatformData::ctFont() const
return m_CTFont.get();
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();
}
......@@ -260,9 +268,9 @@ CTFontRef FontPlatformData::ctFont() const
fontDescriptor = cascadeToLastResortAndDisableSwashesFontDescriptor();
else
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
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) {
int featureTypeValue = kTextSpacingType;
......@@ -271,7 +279,7 @@ CTFontRef FontPlatformData::ctFont() const
RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureTypeValue));
RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureSelectorValue));
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)
m_CTFont = newFont;
......@@ -280,7 +288,7 @@ CTFontRef FontPlatformData::ctFont() const
return m_CTFont.get();
}
SkTypeface* FontPlatformData::typeface() const{
SkTypeface* FontPlatformData::typeface() const {
if (m_typeface)
return m_typeface.get();
......@@ -303,8 +311,9 @@ static bool isAATFont(CTFontRef ctFont)
}
return false;
}
#endif
HarfBuzzFace* FontPlatformData::harfBuzzFace()
HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{
CTFontRef font = ctFont();
// HarfBuzz can't handle AAT font
......@@ -317,14 +326,13 @@ HarfBuzzFace* FontPlatformData::harfBuzzFace()
}
return m_harfBuzzFace.get();
}
#endif
#ifndef NDEBUG
String FontPlatformData::description() const
{
RetainPtr<CFStringRef> cgFontDescription(AdoptCF, CFCopyDescription(cgFont()));
return String(cgFontDescription.get()) + " " + String::number(m_size)
+ (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticOblique ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : "");
return String(cgFontDescription.get()) + " " + String::number(m_textSize)
+ (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticItalic ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : "");
}
#endif
......
......@@ -29,7 +29,7 @@
*/
#include "config.h"
#include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h"
#include "platform/fonts/FontPlatformData.h"
#include "SkTypeface.h"
#include "platform/fonts/harfbuzz/HarfBuzzFace.h"
......@@ -148,7 +148,7 @@ FontPlatformData::~FontPlatformData()
{
}
FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
{
m_typeface = src.m_typeface;
#if !OS(WIN)
......@@ -218,6 +218,11 @@ bool FontPlatformData::isFixedPitch() const
return typeface() && typeface()->isFixedPitch();
}
SkTypeface* FontPlatformData::typeface() const
{
return m_typeface.get();
}
HarfBuzzFace* FontPlatformData::harfBuzzFace() const
{
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()
{
hb_font_t* font = hb_font_create(m_face);
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);
const int scale = (1 << 16) * static_cast<int>(size);
hb_font_set_scale(font, scale, scale);
......
......@@ -34,7 +34,7 @@
#include "SkTypeface.h"
#include "platform/LayoutTestSupport.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h"
#include "platform/fonts/FontPlatformData.h"
#include "platform/graphics/GraphicsContext.h"
#include "public/platform/linux/WebFontRenderStyle.h"
#include "public/platform/linux/WebSandboxSupport.h"
......
......@@ -149,7 +149,7 @@ PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
traits = [fontManager traitsOfFont:nsFont];
if (platformData.m_syntheticBold)
traits |= NSBoldFontMask;
if (platformData.m_syntheticOblique)
if (platformData.m_syntheticItalic)
traits |= NSFontItalicTrait;
weight = [fontManager weightOfFont:nsFont];
size = [nsFont pointSize];
......@@ -179,7 +179,7 @@ PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
FontPlatformData alternateFont(substituteFont, platformData.size(),
isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFontWeight),
(traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTrait),
platformData.m_orientation);
platformData.orientation());
return fontDataFromFontPlatformData(&alternateFont, DoNotRetain);
}
......@@ -220,11 +220,11 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerFont];
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.
// 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())
return 0;
return platformData.leakPtr();
......
......@@ -52,7 +52,7 @@ bool FontPlatformFeatures::canExpandAroundIdeographsInComplexText()
static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Font* font, bool shouldAntialias, bool shouldSmoothFonts)
{
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->setEmbeddedBitmapText(false);
......@@ -60,7 +60,7 @@ static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Fon
paint->setVerticalText(platformData.orientation() == Vertical);
paint->setTypeface(platformData.typeface());
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->setLCDRenderText(shouldSmoothFonts);
paint->setSubpixelText(true);
......
......@@ -131,9 +131,9 @@ const SimpleFontData* SimpleFontData::getCompositeFontReferenceFontData(NSFont *
CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(substituteFont));
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);
if (value) {
CFDictionaryAddValue(dictionary, key, value);
......@@ -215,7 +215,7 @@ void SimpleFontData::platformInit()
iLineGap = CGFontGetLeading(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 descent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize;
float lineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
......@@ -281,7 +281,7 @@ void SimpleFontData::platformCharWidthInit()
if (os2Table && CFDataGetLength(os2Table.get()) >= 4) {
const UInt8* os2 = CFDataGetBytePtr(os2Table.get());
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'));
......@@ -292,7 +292,7 @@ void SimpleFontData::platformCharWidthInit()
SInt16 xMin = static_cast<SInt16>(uxMin);
SInt16 xMax = static_cast<SInt16>(uxMax);
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.
......@@ -315,7 +315,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo
{
if (isCustomFont()) {
FontPlatformData scaledFontData(m_platformData);
scaledFontData.m_size = scaledFontData.m_size * scaleFactor;
scaledFontData.m_textSize = scaledFontData.m_textSize * scaleFactor;
return SimpleFontData::create(scaledFontData, CustomFontData::create());
}
......@@ -332,12 +332,12 @@ PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo
if (m_platformData.m_syntheticBold)
fontTraits |= NSBoldFontMask;
if (m_platformData.m_syntheticOblique)
if (m_platformData.m_syntheticItalic)
fontTraits |= NSItalicFontMask;
NSFontTraitMask scaledFontTraits = [fontManager traitsOfFont:scaledFontData.font()];
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.
return FontCache::fontCache()->fontDataFromFontPlatformData(&scaledFontData);
......@@ -388,7 +388,7 @@ float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
if (font && platformData().isColorBitmapFont())
advance = NSSizeToCGSize([font advancementForGlyph:glyph]);
else {
float pointSize = platformData().m_size;
float pointSize = platformData().m_textSize;
CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, cgFontRenderingModeForNSFont(font), &glyph, 1, &advance)) {
WTF_LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displayName], pointSize);
......
......@@ -37,8 +37,8 @@
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontFaceCreationParams.h"
#include "platform/fonts/FontPlatformData.h"
#include "platform/fonts/SimpleFontData.h"
#include "platform/fonts/harfbuzz/FontPlatformDataHarfbuzz.h"
#include "platform/fonts/win/FontFallbackWin.h"
namespace blink {
......
......@@ -189,7 +189,7 @@ static BOOL betterChoice(NSFontTraitMask desiredTraits, int desiredWeight,
int actualWeight = [fontManager weightOfFont:font];
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,
// 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,
if (syntheticBold)
nonSyntheticTraits &= ~NSBoldFontMask;
if (syntheticOblique)
if (syntheticItalic)
nonSyntheticTraits &= ~NSItalicFontMask;
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