2 * Copyright (C) 2007, 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef CoreTextController_h
27 #define CoreTextController_h
32 #include "GlyphBuffer.h"
33 #include <wtf/RetainPtr.h>
34 #include <wtf/Vector.h>
38 class CoreTextController
{
40 CoreTextController(const Font
*, const TextRun
&, bool mayUseNaturalWritingDirection
= false);
42 // Advance and emit glyphs up to the specified character.
43 void advance(unsigned to
, GlyphBuffer
* = 0);
45 // Compute the character offset for a given x coordinate.
46 int offsetForPosition(int x
, bool includePartialGlyphs
);
48 // Returns the width of everything we've consumed so far.
49 float runWidthSoFar() const { return m_runWidthSoFar
; }
51 float totalWidth() const { return m_totalWidth
; }
53 // Extra width to the left of the leftmost glyph.
54 float finalRoundingWidth() const { return m_finalRoundingWidth
; }
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
);
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
]; }
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
;
82 void collectCoreTextRuns();
83 void collectCoreTextRunsForCharacters(const UChar
*, unsigned length
, unsigned stringLocation
, const SimpleFontData
*);
84 void adjustGlyphsAndAdvances();
88 bool m_mayUseNaturalWritingDirection
;
90 Vector
<UChar
, 256> m_smallCapsBuffer
;
92 Vector
<CoreTextRun
, 16> m_coreTextRuns
;
93 Vector
<CGSize
, 256> m_adjustedAdvances
;
94 Vector
<CGGlyph
, 256> m_adjustedGlyphs
;
96 unsigned m_currentCharacter
;
101 float m_runWidthSoFar
;
102 unsigned m_numGlyphsSoFar
;
104 unsigned m_glyphInCurrentRun
;
105 float m_finalRoundingWidth
;
109 unsigned m_lastRoundingGlyph
;
112 } // namespace WebCore
113 #endif // USE(CORE_TEXT)
114 #endif // CoreTextController_h