Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.h

Issue 2686503003: Add support for shaping a substring to HarfBuzzShaper (Closed)
Patch Set: Clarify API and tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef HarfBuzzShaper_h 31 #ifndef HarfBuzzShaper_h
32 #define HarfBuzzShaper_h 32 #define HarfBuzzShaper_h
33 33
34 #include <hb.h>
35 #include <unicode/uscript.h>
36 #include <memory>
37 #include "platform/fonts/shaping/RunSegmenter.h"
34 #include "platform/fonts/shaping/ShapeResult.h" 38 #include "platform/fonts/shaping/ShapeResult.h"
35 #include "platform/text/TextRun.h" 39 #include "platform/text/TextRun.h"
36 #include "wtf/Allocator.h" 40 #include "wtf/Allocator.h"
37 #include "wtf/Deque.h" 41 #include "wtf/Deque.h"
38 #include "wtf/Vector.h" 42 #include "wtf/Vector.h"
39 #include <hb.h>
40 #include <memory>
41 #include <unicode/uscript.h>
42 43
43 namespace blink { 44 namespace blink {
44 45
45 class Font; 46 class Font;
46 class SimpleFontData; 47 class SimpleFontData;
47 class HarfBuzzShaper; 48 class HarfBuzzShaper;
49 struct HolesQueueItem;
48 50
49 class PLATFORM_EXPORT HarfBuzzShaper final { 51 class PLATFORM_EXPORT HarfBuzzShaper final {
50 public: 52 public:
51 HarfBuzzShaper(const UChar*, unsigned length, TextDirection); 53 HarfBuzzShaper(const UChar*, unsigned length);
52 PassRefPtr<ShapeResult> shapeResult(const Font*) const; 54
55 // Shape a range, defined by the start and end parameters, of the string
56 // supplied to the constructor.
57 // The start and end positions should represent boundaries where a break may
58 // occur, such as at the beginning or end of lines or at element boundaries.
59 // If given arbitrary positions the results are not guaranteed to be correct.
60 // May be called multiple times; font and direction may vary between calls.
61 PassRefPtr<ShapeResult> shape(const Font*,
62 TextDirection,
63 unsigned start,
64 unsigned end) const;
65
66 // Shape the entire string with a single font and direction.
67 // Equivalent to calling the range version with a start offset of zero and an
68 // end offset equal to the length.
69 PassRefPtr<ShapeResult> shape(const Font*, TextDirection) const;
70
53 ~HarfBuzzShaper() {} 71 ~HarfBuzzShaper() {}
54 72
55 enum HolesQueueItemAction { HolesQueueNextFont, HolesQueueRange }; 73 private:
74 using FeaturesVector = Vector<hb_feature_t, 6>;
56 75
57 struct HolesQueueItem { 76 // Shapes a single seqment, as identified by the RunSegmenterRange parameter,
58 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 77 // one or more times taking font fallback into account. The start and end
59 HolesQueueItemAction m_action; 78 // parameters are for the entire text run, not the segment, and are used to
60 unsigned m_startIndex; 79 // determine pre- and post-context for shaping.
61 unsigned m_numCharacters; 80 void shapeSegment(ShapeResult*,
62 HolesQueueItem(HolesQueueItemAction action, unsigned start, unsigned num) 81 Deque<HolesQueueItem>*,
63 : m_action(action), m_startIndex(start), m_numCharacters(num){}; 82 hb_buffer_t*,
64 }; 83 const Font*,
84 TextDirection,
85 FeaturesVector*,
86 RunSegmenter::RunSegmenterRange,
87 unsigned start,
88 unsigned end) const;
65 89
66 private:
67 bool extractShapeResults(hb_buffer_t*, 90 bool extractShapeResults(hb_buffer_t*,
68 ShapeResult*, 91 ShapeResult*,
69 bool& fontCycleQueued, 92 bool& fontCycleQueued,
70 Deque<HolesQueueItem>*, 93 Deque<HolesQueueItem>*,
71 const HolesQueueItem&, 94 const HolesQueueItem&,
72 const Font*, 95 const Font*,
96 TextDirection,
73 const SimpleFontData*, 97 const SimpleFontData*,
74 UScriptCode, 98 UScriptCode,
75 bool isLastResort) const; 99 bool isLastResort) const;
76 bool collectFallbackHintChars(const Deque<HolesQueueItem>&, 100 bool collectFallbackHintChars(const Deque<HolesQueueItem>*,
77 Vector<UChar32>& hint) const; 101 Vector<UChar32>& hint) const;
78 102
79 const UChar* m_normalizedBuffer; 103 const UChar* m_text;
80 unsigned m_normalizedBufferLength; 104 unsigned m_textLength;
81 TextDirection m_textDirection;
82 }; 105 };
83 106
84 } // namespace blink 107 } // namespace blink
85 108
86 #endif // HarfBuzzShaper_h 109 #endif // HarfBuzzShaper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698