Font.h revision ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb
18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *           (C) 2000 Antti Koivisto (koivisto@kde.org)
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *           (C) 2000 Dirk Mueller (mueller@kde.org)
56c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen * Copyright (C) 2003, 2006, 2007, 2010 Apple Inc. All rights reserved.
6635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Copyright (C) 2008 Holger Hans Peter Freyther
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is free software; you can redistribute it and/or
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modify it under the terms of the GNU Library General Public
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License as published by the Free Software Foundation; either
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * version 2 of the License, or (at your option) any later version.
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is distributed in the hope that it will be useful,
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Library General Public License for more details.
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * You should have received a copy of the GNU Library General Public License
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * along with this library; see the file COPYING.LIB.  If not, write to
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Boston, MA 02110-1301, USA.
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef Font_h
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define Font_h
278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
28d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "CharacterNames.h"
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "FontDescription.h"
306c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen#include "FontFallbackList.h"
31635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include "SimpleFontData.h"
32d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "TypesettingFeatures.h"
338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/HashMap.h>
34d0825bca7fe65beaee391d30da42e937db621564Steve Block#include <wtf/HashSet.h>
35635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <wtf/MathExtras.h>
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#if PLATFORM(QT)
38635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <QFont>
398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass FloatPoint;
448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass FloatRect;
458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass FontData;
468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass FontFallbackList;
478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass FontPlatformData;
488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass FontSelector;
498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass GlyphBuffer;
508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass GlyphPageTreeNode;
518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass GraphicsContext;
528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SVGFontElement;
53ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochclass TextRun;
548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstruct GlyphData;
568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
57635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectconst unsigned defaultUnitsPerEm = 1000;
58635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
59dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockstruct GlyphOverflow {
60dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    GlyphOverflow()
61dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        : left(0)
62dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        , right(0)
63dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        , top(0)
64dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        , bottom(0)
65dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    {
66dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    }
67dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
68dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    int left;
69dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    int right;
70dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    int top;
71dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    int bottom;
72dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block};
73dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass Font {
758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic:
768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Font();
778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Font(const FontDescription&, short letterSpacing, short wordSpacing);
78635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    // This constructor is only used if the platform wants to start with a native font.
79967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch    Font(const FontPlatformData&, bool isPrinting, FontSmoothingMode = AutoSmoothing);
808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    ~Font();
818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Font(const Font&);
838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Font& operator=(const Font&);
848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool operator==(const Font& other) const;
8621939df44de1705786c545cd1bf519d47250322dBen Murdoch    bool operator!=(const Font& other) const { return !(*this == other); }
878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    const FontDescription& fontDescription() const { return m_fontDescription; }
898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int pixelSize() const { return fontDescription().computedPixelSize(); }
918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    float size() const { return fontDescription().computedSize(); }
928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void update(PassRefPtr<FontSelector>) const;
948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void drawText(GraphicsContext*, const TextRun&, const FloatPoint&, int from = 0, int to = -1) const;
96f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    void drawEmphasisMarks(GraphicsContext*, const TextRun&, const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1) const;
978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
98dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    int width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* glyphOverflow = 0) const { return lroundf(floatWidth(run, fallbackFonts, glyphOverflow)); }
99dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    float floatWidth(const TextRun&, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* glyphOverflow = 0) const;
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    float floatWidth(const TextRun& run, int extraCharsAvailable, int& charsConsumed, String& glyphName) const;
1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    int offsetForPosition(const TextRun&, float position, bool includePartialGlyphs) const;
10306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    FloatRect selectionRectForText(const TextRun&, const FloatPoint&, int h, int from = 0, int to = -1) const;
1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool isSmallCaps() const { return m_fontDescription.smallCaps(); }
1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    short wordSpacing() const { return m_wordSpacing; }
1088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    short letterSpacing() const { return m_letterSpacing; }
1098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void setWordSpacing(short s) { m_wordSpacing = s; }
1108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void setLetterSpacing(short s) { m_letterSpacing = s; }
1118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool isFixedPitch() const;
1128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool isPrinterFont() const { return m_fontDescription.usePrinterFont(); }
1138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    FontRenderingMode renderingMode() const { return m_fontDescription.renderingMode(); }
1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
116d0825bca7fe65beaee391d30da42e937db621564Steve Block    TypesettingFeatures typesettingFeatures() const
117d0825bca7fe65beaee391d30da42e937db621564Steve Block    {
118d0825bca7fe65beaee391d30da42e937db621564Steve Block        TextRenderingMode textRenderingMode = m_fontDescription.textRenderingMode();
119d0825bca7fe65beaee391d30da42e937db621564Steve Block        return textRenderingMode == OptimizeLegibility || textRenderingMode == GeometricPrecision ? Kerning | Ligatures : 0;
120d0825bca7fe65beaee391d30da42e937db621564Steve Block    }
121d0825bca7fe65beaee391d30da42e937db621564Steve Block
1228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    FontFamily& firstFamily() { return m_fontDescription.firstFamily(); }
1238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    const FontFamily& family() const { return m_fontDescription.family(); }
1248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool italic() const { return m_fontDescription.italic(); }
1268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    FontWeight weight() const { return m_fontDescription.weight(); }
1278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool isPlatformFont() const { return m_isPlatformFont; }
1298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Metrics that we query the FontFallbackList for.
1316b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner    int ascent(FontBaseline baselineType = AlphabeticBaseline) const { return primaryFont()->ascent(baselineType); }
1326b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner    int descent(FontBaseline baselineType = AlphabeticBaseline) const { return primaryFont()->descent(baselineType); }
1338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int height() const { return ascent() + descent(); }
134635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    int lineSpacing() const { return primaryFont()->lineSpacing(); }
135635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    int lineGap() const { return primaryFont()->lineGap(); }
136635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    float xHeight() const { return primaryFont()->xHeight(); }
137635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    unsigned unitsPerEm() const { return primaryFont()->unitsPerEm(); }
1385f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    int spaceWidth() const { return (int)ceilf(primaryFont()->adjustedSpaceWidth() + m_letterSpacing); }
139967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch    float tabWidth(const SimpleFontData& fontData) const { return 8 * ceilf(fontData.adjustedSpaceWidth() + letterSpacing()); }
140f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    int emphasisMarkAscent(const AtomicString&) const;
141f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    int emphasisMarkDescent(const AtomicString&) const;
142f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    int emphasisMarkHeight(const AtomicString&) const;
1438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1440bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    const SimpleFontData* primaryFont() const;
1458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    const FontData* fontDataAt(unsigned) const;
146f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    GlyphData glyphDataForCharacter(UChar32, bool mirror, FontDataVariant = AutoVariant) const;
147cad810f21b803229eb11403f9209855525a25d57Steve Block    bool primaryFontHasGlyphForCharacter(UChar32) const;
1488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Used for complex text, and does not utilize the glyph map cache.
1498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    const FontData* fontDataForCharacters(const UChar*, int length) const;
1508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1516b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner    static bool isCJKIdeograph(UChar32);
152f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    static bool isCJKIdeographOrSymbol(UChar32);
1536b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner
154635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#if PLATFORM(QT)
155635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    QFont font() const;
156635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#endif
157635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
1585f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    static void setShouldUseSmoothing(bool);
1595f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    static bool shouldUseSmoothing();
1605f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
16121939df44de1705786c545cd1bf519d47250322dBen Murdoch    enum CodePath { Auto, Simple, Complex, SimpleWithGlyphOverflow };
16221939df44de1705786c545cd1bf519d47250322dBen Murdoch
1638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate:
1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#if ENABLE(SVG_FONTS)
1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void drawTextUsingSVGFont(GraphicsContext*, const TextRun&, const FloatPoint&, int from, int to) const;
1668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    float floatWidthUsingSVGFont(const TextRun&) const;
1678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    float floatWidthUsingSVGFont(const TextRun&, int extraCharsAvailable, int& charsConsumed, String& glyphName) const;
16806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    FloatRect selectionRectForTextUsingSVGFont(const TextRun&, const FloatPoint&, int h, int from, int to) const;
16906ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    int offsetForPositionForTextUsingSVGFont(const TextRun&, float position, bool includePartialGlyphs) const;
1708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
171635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
172f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    enum ForTextEmphasisOrNot { NotForTextEmphasis, ForTextEmphasis };
173f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch
174f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    // Returns the initial in-stream advance.
175f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    float getGlyphsAndAdvancesForSimpleText(const TextRun&, int from, int to, GlyphBuffer&, ForTextEmphasisOrNot = NotForTextEmphasis) const;
176635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    void drawSimpleText(GraphicsContext*, const TextRun&, const FloatPoint&, int from, int to) const;
177f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    void drawEmphasisMarksForSimpleText(GraphicsContext*, const TextRun&, const AtomicString& mark, const FloatPoint&, int from, int to) const;
1788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void drawGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
179f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    void drawGlyphBuffer(GraphicsContext*, const GlyphBuffer&, const FloatPoint&) const;
180f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    void drawEmphasisMarks(GraphicsContext* context, const GlyphBuffer&, const AtomicString&, const FloatPoint&) const;
18121939df44de1705786c545cd1bf519d47250322dBen Murdoch    float floatWidthForSimpleText(const TextRun&, GlyphBuffer*, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
18206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    int offsetForPositionForSimpleText(const TextRun&, float position, bool includePartialGlyphs) const;
18306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    FloatRect selectionRectForSimpleText(const TextRun&, const FloatPoint&, int h, int from, int to) const;
1845f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
185f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    bool getEmphasisMarkGlyphData(const AtomicString&, GlyphData&) const;
186f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch
1875f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    static bool canReturnFallbackFontsForComplexText();
188635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
189545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    CodePath codePath(const TextRun&) const;
190f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch
191f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    // Returns the initial in-stream advance.
192f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    float getGlyphsAndAdvancesForComplexText(const TextRun&, int from, int to, GlyphBuffer&, ForTextEmphasisOrNot = NotForTextEmphasis) const;
193635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    void drawComplexText(GraphicsContext*, const TextRun&, const FloatPoint&, int from, int to) const;
194f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    void drawEmphasisMarksForComplexText(GraphicsContext*, const TextRun&, const AtomicString& mark, const FloatPoint&, int from, int to) const;
195dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    float floatWidthForComplexText(const TextRun&, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
19606ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const;
19706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    FloatRect selectionRectForComplexText(const TextRun&, const FloatPoint&, int h, int from, int to) const;
198635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
1998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    friend struct WidthIterator;
2008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic:
2028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Useful for debugging the different font rendering code paths.
2038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static void setCodePath(CodePath);
2048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static CodePath codePath();
2058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static CodePath s_codePath;
2068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static const uint8_t gRoundingHackCharacterTable[256];
2088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static bool isRoundingHackCharacter(UChar32 c)
2098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    {
2108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return (((c & ~0xFF) == 0 && gRoundingHackCharacterTable[c]));
2118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
2128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    FontSelector* fontSelector() const;
214bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    static bool treatAsSpace(UChar c) { return c == ' ' || c == '\t' || c == '\n' || c == noBreakSpace; }
215bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    static bool treatAsZeroWidthSpace(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == softHyphen || (c >= 0x200c && c <= 0x200f) || (c >= 0x202a && c <= 0x202e) || c == objectReplacementCharacter; }
216f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch    static bool canReceiveTextEmphasis(UChar32 c);
2178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
218d0825bca7fe65beaee391d30da42e937db621564Steve Block    static inline UChar normalizeSpaces(UChar character)
219d0825bca7fe65beaee391d30da42e937db621564Steve Block    {
220d0825bca7fe65beaee391d30da42e937db621564Steve Block        if (treatAsSpace(character))
221d0825bca7fe65beaee391d30da42e937db621564Steve Block            return space;
222d0825bca7fe65beaee391d30da42e937db621564Steve Block
223d0825bca7fe65beaee391d30da42e937db621564Steve Block        if (treatAsZeroWidthSpace(character))
224d0825bca7fe65beaee391d30da42e937db621564Steve Block            return zeroWidthSpace;
225d0825bca7fe65beaee391d30da42e937db621564Steve Block
226d0825bca7fe65beaee391d30da42e937db621564Steve Block        return character;
227d0825bca7fe65beaee391d30da42e937db621564Steve Block    }
228d0825bca7fe65beaee391d30da42e937db621564Steve Block
229d0825bca7fe65beaee391d30da42e937db621564Steve Block    static String normalizeSpaces(const String&);
230d0825bca7fe65beaee391d30da42e937db621564Steve Block
2318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#if ENABLE(SVG_FONTS)
2328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool isSVGFont() const;
2338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SVGFontElement* svgFont() const;
2348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
2358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
236e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block    bool needsTranscoding() const { return m_needsTranscoding; }
237e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block
2388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate:
239cad810f21b803229eb11403f9209855525a25d57Steve Block    bool loadingCustomFonts() const
240cad810f21b803229eb11403f9209855525a25d57Steve Block    {
241cad810f21b803229eb11403f9209855525a25d57Steve Block        return m_fontList && m_fontList->loadingCustomFonts();
242cad810f21b803229eb11403f9209855525a25d57Steve Block    }
243cad810f21b803229eb11403f9209855525a25d57Steve Block
2448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    FontDescription m_fontDescription;
2458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    mutable RefPtr<FontFallbackList> m_fontList;
2468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    short m_letterSpacing;
2478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    short m_wordSpacing;
2488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool m_isPlatformFont;
249e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block    bool m_needsTranscoding;
2508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project};
2518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2526c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monseninline Font::~Font()
2536c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen{
2546c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen}
2556c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
2566c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monseninline const SimpleFontData* Font::primaryFont() const
2576c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen{
2586c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    ASSERT(m_fontList);
2596c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    return m_fontList->primarySimpleFontData(this);
2606c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen}
2616c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
2626c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monseninline const FontData* Font::fontDataAt(unsigned index) const
2636c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen{
2646c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    ASSERT(m_fontList);
2656c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    return m_fontList->fontDataAt(this, index);
2666c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen}
2676c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
2686c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monseninline const FontData* Font::fontDataForCharacters(const UChar* characters, int length) const
2696c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen{
2706c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    ASSERT(m_fontList);
2716c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    return m_fontList->fontDataForCharacters(this, characters, length);
2726c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen}
2736c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
2746c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monseninline bool Font::isFixedPitch() const
2756c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen{
2766c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    ASSERT(m_fontList);
2776c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    return m_fontList->isFixedPitch(this);
2786c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen}
2796c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
2806c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monseninline FontSelector* Font::fontSelector() const
2816c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen{
2826c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    return m_fontList ? m_fontList->fontSelector() : 0;
2836c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen}
2846c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
2858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
288