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

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: Cleanup comments and adjust tolerance 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, TextDirection);
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. May be called multiple times and the font may
57 // may vary between calls.
58 PassRefPtr<ShapeResult> shape(const Font*,
59 unsigned start,
60 unsigned end) const;
61
62 // Shape the entire string with a single font..
63 // Equivalent to calling the range version with a start offset of zero and an
64 // end offset equal to the length.
65 PassRefPtr<ShapeResult> shape(const Font*) const;
66
53 ~HarfBuzzShaper() {} 67 ~HarfBuzzShaper() {}
54 68
55 enum HolesQueueItemAction { HolesQueueNextFont, HolesQueueRange }; 69 private:
70 using FeaturesVector = Vector<hb_feature_t, 6>;
56 71
57 struct HolesQueueItem { 72 // Shapes a single seqment, as identified by the RunSegmenterRange parameter,
58 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 73 // one or more times taking font fallback into account. The start and end
59 HolesQueueItemAction m_action; 74 // parameters are for the entire text run, not the segment, and are used to
60 unsigned m_startIndex; 75 // determine pre- and post-context for shaping.
61 unsigned m_numCharacters; 76 void shapeSegment(ShapeResult*,
62 HolesQueueItem(HolesQueueItemAction action, unsigned start, unsigned num) 77 Deque<HolesQueueItem>*,
63 : m_action(action), m_startIndex(start), m_numCharacters(num){}; 78 hb_buffer_t*,
64 }; 79 const Font*,
80 FeaturesVector*,
81 RunSegmenter::RunSegmenterRange,
82 unsigned start,
83 unsigned end) const;
65 84
66 private:
67 bool extractShapeResults(hb_buffer_t*, 85 bool extractShapeResults(hb_buffer_t*,
68 ShapeResult*, 86 ShapeResult*,
69 bool& fontCycleQueued, 87 bool& fontCycleQueued,
70 Deque<HolesQueueItem>*, 88 Deque<HolesQueueItem>*,
71 const HolesQueueItem&, 89 const HolesQueueItem&,
72 const Font*, 90 const Font*,
73 const SimpleFontData*, 91 const SimpleFontData*,
74 UScriptCode, 92 UScriptCode,
75 bool isLastResort) const; 93 bool isLastResort) const;
76 bool collectFallbackHintChars(const Deque<HolesQueueItem>&, 94 bool collectFallbackHintChars(const Deque<HolesQueueItem>*,
77 Vector<UChar32>& hint) const; 95 Vector<UChar32>& hint) const;
78 96
79 const UChar* m_normalizedBuffer; 97 const UChar* m_text;
80 unsigned m_normalizedBufferLength; 98 unsigned m_textLength;
81 TextDirection m_textDirection; 99 TextDirection m_paragraphDirection;
82 }; 100 };
83 101
84 } // namespace blink 102 } // namespace blink
85 103
86 #endif // HarfBuzzShaper_h 104 #endif // HarfBuzzShaper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698