]> git.saurik.com Git - iphone-api.git/blob - WebCore/CoreTextController.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / CoreTextController.h
1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef CoreTextController_h
27 #define CoreTextController_h
28
29 #if USE(CORE_TEXT)
30
31 #include "Font.h"
32 #include "GlyphBuffer.h"
33 #include <wtf/RetainPtr.h>
34 #include <wtf/Vector.h>
35
36 namespace WebCore {
37
38 class CoreTextController {
39 public:
40 CoreTextController(const Font*, const TextRun&, bool mayUseNaturalWritingDirection = false);
41
42 // Advance and emit glyphs up to the specified character.
43 void advance(unsigned to, GlyphBuffer* = 0);
44
45 // Compute the character offset for a given x coordinate.
46 int offsetForPosition(int x, bool includePartialGlyphs);
47
48 // Returns the width of everything we've consumed so far.
49 float runWidthSoFar() const { return m_runWidthSoFar; }
50
51 float totalWidth() const { return m_totalWidth; }
52
53 // Extra width to the left of the leftmost glyph.
54 float finalRoundingWidth() const { return m_finalRoundingWidth; }
55
56 private:
57 class CoreTextRun {
58 public:
59 CoreTextRun(CTRunRef, const SimpleFontData*, const UChar* characters, unsigned stringLocation, size_t stringLength);
60 CoreTextRun(const SimpleFontData*, const UChar* characters, unsigned stringLocation, size_t stringLength, bool ltr);
61
62 CTRunRef ctRun() const { return m_CTRun.get(); }
63 unsigned glyphCount() const { return m_glyphCount; }
64 const SimpleFontData* fontData() const { return m_fontData; }
65 const UChar* characters() const { return m_characters; }
66 unsigned stringLocation() const { return m_stringLocation; }
67 size_t stringLength() const { return m_stringLength; }
68 CFIndex indexAt(size_t i) const { return m_indices[i]; }
69
70 private:
71 RetainPtr<CTRunRef> m_CTRun;
72 unsigned m_glyphCount;
73 const SimpleFontData* m_fontData;
74 const UChar* m_characters;
75 unsigned m_stringLocation;
76 size_t m_stringLength;
77 const CFIndex* m_indices;
78 // Used only if CTRunGet*Ptr fails or if this is a missing glyphs run.
79 RetainPtr<CFMutableDataRef> m_indicesData;
80 };
81
82 void collectCoreTextRuns();
83 void collectCoreTextRunsForCharacters(const UChar*, unsigned length, unsigned stringLocation, const SimpleFontData*);
84 void adjustGlyphsAndAdvances();
85
86 const Font& m_font;
87 const TextRun& m_run;
88 bool m_mayUseNaturalWritingDirection;
89
90 Vector<UChar, 256> m_smallCapsBuffer;
91
92 Vector<CoreTextRun, 16> m_coreTextRuns;
93 Vector<CGSize, 256> m_adjustedAdvances;
94 Vector<CGGlyph, 256> m_adjustedGlyphs;
95
96 unsigned m_currentCharacter;
97 int m_end;
98
99 CGFloat m_totalWidth;
100
101 float m_runWidthSoFar;
102 unsigned m_numGlyphsSoFar;
103 size_t m_currentRun;
104 unsigned m_glyphInCurrentRun;
105 float m_finalRoundingWidth;
106 float m_padding;
107 float m_padPerSpace;
108
109 unsigned m_lastRoundingGlyph;
110 };
111
112 } // namespace WebCore
113 #endif // USE(CORE_TEXT)
114 #endif // CoreTextController_h