OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 20 matching lines...) Expand all Loading... |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/rendering/TextRunConstructor.h" | 32 #include "core/rendering/TextRunConstructor.h" |
33 | 33 |
34 #include "core/rendering/RenderText.h" | 34 #include "core/rendering/RenderText.h" |
35 #include "core/rendering/style/RenderStyle.h" | 35 #include "core/rendering/style/RenderStyle.h" |
36 #include "platform/text/BidiTextRun.h" | 36 #include "platform/text/BidiTextRun.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 template <typename CharacterType> | 40 template <typename CharacterType> |
41 static inline TextRun constructTextRunInternal(RenderObject* context, const Font
& font, const CharacterType* characters, int length, RenderStyle* style, TextDir
ection direction) | 41 static inline TextRun constructTextRunInternal(RenderObject* context, const Font
& font, const CharacterType* characters, int length, const RenderStyle* style, T
extDirection direction) |
42 { | 42 { |
43 ASSERT(style); | 43 ASSERT(style); |
44 TextRun::ExpansionBehavior expansion = TextRun::AllowTrailingExpansion | Tex
tRun::ForbidLeadingExpansion; | 44 TextRun::ExpansionBehavior expansion = TextRun::AllowTrailingExpansion | Tex
tRun::ForbidLeadingExpansion; |
45 bool directionalOverride = style->rtlOrdering() == VisualOrder; | 45 bool directionalOverride = style->rtlOrdering() == VisualOrder; |
46 TextRun run(characters, length, 0, 0, expansion, direction, directionalOverr
ide); | 46 TextRun run(characters, length, 0, 0, expansion, direction, directionalOverr
ide); |
47 return run; | 47 return run; |
48 } | 48 } |
49 | 49 |
50 template <typename CharacterType> | 50 template <typename CharacterType> |
51 static inline TextRun constructTextRunInternal(RenderObject* context, const Font
& font, const CharacterType* characters, int length, RenderStyle* style, TextDir
ection direction, TextRunFlags flags) | 51 static inline TextRun constructTextRunInternal(RenderObject* context, const Font
& font, const CharacterType* characters, int length, const RenderStyle* style, T
extDirection direction, TextRunFlags flags) |
52 { | 52 { |
53 ASSERT(style); | 53 ASSERT(style); |
54 | 54 |
55 TextDirection textDirection = direction; | 55 TextDirection textDirection = direction; |
56 bool directionalOverride = style->rtlOrdering() == VisualOrder; | 56 bool directionalOverride = style->rtlOrdering() == VisualOrder; |
57 if (flags != DefaultTextRunFlags) { | 57 if (flags != DefaultTextRunFlags) { |
58 if (flags & RespectDirection) | 58 if (flags & RespectDirection) |
59 textDirection = style->direction(); | 59 textDirection = style->direction(); |
60 if (flags & RespectDirectionOverride) | 60 if (flags & RespectDirectionOverride) |
61 directionalOverride |= isOverride(style->unicodeBidi()); | 61 directionalOverride |= isOverride(style->unicodeBidi()); |
62 } | 62 } |
63 | 63 |
64 TextRun::ExpansionBehavior expansion = TextRun::AllowTrailingExpansion | Tex
tRun::ForbidLeadingExpansion; | 64 TextRun::ExpansionBehavior expansion = TextRun::AllowTrailingExpansion | Tex
tRun::ForbidLeadingExpansion; |
65 TextRun run(characters, length, 0, 0, expansion, textDirection, directionalO
verride); | 65 TextRun run(characters, length, 0, 0, expansion, textDirection, directionalO
verride); |
66 return run; | 66 return run; |
67 } | 67 } |
68 | 68 |
69 TextRun constructTextRun(RenderObject* context, const Font& font, const LChar* c
haracters, int length, RenderStyle* style, TextDirection direction) | 69 TextRun constructTextRun(RenderObject* context, const Font& font, const LChar* c
haracters, int length, const RenderStyle* style, TextDirection direction) |
70 { | 70 { |
71 return constructTextRunInternal(context, font, characters, length, style, di
rection); | 71 return constructTextRunInternal(context, font, characters, length, style, di
rection); |
72 } | 72 } |
73 | 73 |
74 TextRun constructTextRun(RenderObject* context, const Font& font, const UChar* c
haracters, int length, RenderStyle* style, TextDirection direction) | 74 TextRun constructTextRun(RenderObject* context, const Font& font, const UChar* c
haracters, int length, const RenderStyle* style, TextDirection direction) |
75 { | 75 { |
76 return constructTextRunInternal(context, font, characters, length, style, di
rection); | 76 return constructTextRunInternal(context, font, characters, length, style, di
rection); |
77 } | 77 } |
78 | 78 |
79 TextRun constructTextRun(RenderObject* context, const Font& font, const RenderTe
xt* text, RenderStyle* style, TextDirection direction) | 79 TextRun constructTextRun(RenderObject* context, const Font& font, const RenderTe
xt* text, const RenderStyle* style, TextDirection direction) |
80 { | 80 { |
81 if (text->is8Bit()) | 81 if (text->is8Bit()) |
82 return constructTextRunInternal(context, font, text->characters8(), text
->textLength(), style, direction); | 82 return constructTextRunInternal(context, font, text->characters8(), text
->textLength(), style, direction); |
83 return constructTextRunInternal(context, font, text->characters16(), text->t
extLength(), style, direction); | 83 return constructTextRunInternal(context, font, text->characters16(), text->t
extLength(), style, direction); |
84 } | 84 } |
85 | 85 |
86 TextRun constructTextRun(RenderObject* context, const Font& font, const RenderTe
xt* text, unsigned offset, unsigned length, RenderStyle* style, TextDirection di
rection) | 86 TextRun constructTextRun(RenderObject* context, const Font& font, const RenderTe
xt* text, unsigned offset, unsigned length, const RenderStyle* style, TextDirect
ion direction) |
87 { | 87 { |
88 ASSERT(offset + length <= text->textLength()); | 88 ASSERT(offset + length <= text->textLength()); |
89 if (text->is8Bit()) | 89 if (text->is8Bit()) |
90 return constructTextRunInternal(context, font, text->characters8() + off
set, length, style, direction); | 90 return constructTextRunInternal(context, font, text->characters8() + off
set, length, style, direction); |
91 return constructTextRunInternal(context, font, text->characters16() + offset
, length, style, direction); | 91 return constructTextRunInternal(context, font, text->characters16() + offset
, length, style, direction); |
92 } | 92 } |
93 | 93 |
94 TextRun constructTextRun(RenderObject* context, const Font& font, const String&
string, RenderStyle* style, TextDirection direction, TextRunFlags flags) | 94 TextRun constructTextRun(RenderObject* context, const Font& font, const String&
string, const RenderStyle* style, TextDirection direction, TextRunFlags flags) |
95 { | 95 { |
96 unsigned length = string.length(); | 96 unsigned length = string.length(); |
97 if (!length) | 97 if (!length) |
98 return constructTextRunInternal(context, font, static_cast<const LChar*>
(0), length, style, direction, flags); | 98 return constructTextRunInternal(context, font, static_cast<const LChar*>
(0), length, style, direction, flags); |
99 if (string.is8Bit()) | 99 if (string.is8Bit()) |
100 return constructTextRunInternal(context, font, string.characters8(), len
gth, style, direction, flags); | 100 return constructTextRunInternal(context, font, string.characters8(), len
gth, style, direction, flags); |
101 return constructTextRunInternal(context, font, string.characters16(), length
, style, direction, flags); | 101 return constructTextRunInternal(context, font, string.characters16(), length
, style, direction, flags); |
102 } | 102 } |
103 | 103 |
104 TextRun constructTextRun(RenderObject* context, const Font& font, const String&
string, RenderStyle* style, TextRunFlags flags) | 104 TextRun constructTextRun(RenderObject* context, const Font& font, const String&
string, const RenderStyle* style, TextRunFlags flags) |
105 { | 105 { |
106 bool hasStrongDirectionality; | 106 bool hasStrongDirectionality; |
107 return constructTextRun(context, font, string, style, determineDirectionalit
y(string, hasStrongDirectionality), flags); | 107 return constructTextRun(context, font, string, style, determineDirectionalit
y(string, hasStrongDirectionality), flags); |
108 } | 108 } |
109 | 109 |
110 TextRun constructTextRun(RenderObject* context, const Font& font, const RenderTe
xt* text, unsigned offset, unsigned length, RenderStyle* style) | 110 TextRun constructTextRun(RenderObject* context, const Font& font, const RenderTe
xt* text, unsigned offset, unsigned length, const RenderStyle* style) |
111 { | 111 { |
112 ASSERT(offset + length <= text->textLength()); | 112 ASSERT(offset + length <= text->textLength()); |
113 TextRun run = text->is8Bit() | 113 TextRun run = text->is8Bit() |
114 ? constructTextRunInternal(context, font, text->characters8() + offset,
length, style, LTR) | 114 ? constructTextRunInternal(context, font, text->characters8() + offset,
length, style, LTR) |
115 : constructTextRunInternal(context, font, text->characters16() + offset,
length, style, LTR); | 115 : constructTextRunInternal(context, font, text->characters16() + offset,
length, style, LTR); |
116 bool hasStrongDirectionality; | 116 bool hasStrongDirectionality; |
117 run.setDirection(directionForRun(run, hasStrongDirectionality)); | 117 run.setDirection(directionForRun(run, hasStrongDirectionality)); |
118 return run; | 118 return run; |
119 } | 119 } |
120 | 120 |
121 } // namespace blink | 121 } // namespace blink |
OLD | NEW |