49 TextRun begin(run.characters(), from); |
49 TextRun begin(run.characters(), from); |
50 b = floatWidthForComplexText(begin, style); |
50 b = floatWidthForComplexText(begin, style); |
51 } |
51 } |
52 |
52 |
53 TextRun end(run.characters() + from, to - from); |
53 TextRun end(run.characters() + from, to - from); |
54 float w = floatWidthForComplexText(end, style); |
54 float w = floatWidthForComplexText(end, style); |
55 |
55 |
56 FloatRect rect(b + point.x(), point.y(), w, h); |
56 FloatRect rect(b + point.x(), point.y(), w, h); |
57 |
57 |
58 return rect; |
58 return rect; |
59 } |
59 } |
60 |
60 |
61 void Font::drawComplexText(GraphicsContext* graphicsContext, const TextRun& run, const TextStyle& style, const FloatPoint& point, int from, int to) const |
61 void Font::drawComplexText(GraphicsContext* graphicsContext, const TextRun& run, const TextStyle& style, const FloatPoint& point, int from, int to) const |
62 { |
62 { |
63 PlatformFontCache* cache = StaticObjectsContainer::instance()->fontCache(); |
63 PlatformFontCache* cache = StaticObjectsContainer::instance()->fontCache(); |
64 CFont* font = cache->zoomedFont(m_fontDescription, cache->fontZoomFactor()); |
64 CFont* font = cache->zoomedFont(m_fontDescription, cache->fontZoomFactor()); |
65 // RenderBlock::layoutColumns create a 0 platform context to do a faked paint |
65 // RenderBlock::layoutColumns create a 0 platform context to do a faked paint |
66 // during layout - weird stuff :) |
66 // during layout - weird stuff :) |
72 bitgc.SetPenColor( TRgb( c.red(), c.green(), c.blue(), c.alpha() ) ); |
72 bitgc.SetPenColor( TRgb( c.red(), c.green(), c.blue(), c.alpha() ) ); |
73 bitgc.UseFontNoDuplicate( static_cast<const CFbsBitGcFont*>(font) ); |
73 bitgc.UseFontNoDuplicate( static_cast<const CFbsBitGcFont*>(font) ); |
74 |
74 |
75 TPoint startPos = point; |
75 TPoint startPos = point; |
76 if (from) { |
76 if (from) { |
77 |
77 |
78 // the text run before the selection |
78 // the text run before the selection |
79 TextRun leftRun(run.characters(), from); |
79 TextRun leftRun(run.characters(), from); |
80 // the selection start point |
80 // the selection start point |
81 startPos.iX += floatWidthForComplexText(leftRun, style); |
81 startPos.iX += floatWidthForComplexText(leftRun, style); |
82 } |
82 } |
83 |
83 |
84 TPtrC str( (const TUint16*)(run.characters() + from), to - from); |
84 TPtrC str( (const TUint16*)(run.characters() + from), to - from); |
85 |
85 |
86 TInt numSpaces(0); |
86 TInt numSpaces(0); |
87 TInt indexOfFirstNonRegularSpace(-1); |
87 TInt indexOfFirstNonRegularSpace(-1); |
88 TInt strLength(str.Length()); |
88 TInt strLength(str.Length()); |
89 |
89 |
90 // a) search for nbsp and similar |
90 // a) search for nbsp and similar |
91 // b) count the spaces for word spacing |
91 // b) count the spaces for word spacing |
92 for( TInt n = 0; n<strLength; ++n) { |
92 for( TInt n = 0; n<strLength; ++n) { |
93 |
93 |
94 if ( str[n] == ' ' ) { |
94 if ( str[n] == ' ' ) { |
95 numSpaces++; |
95 numSpaces++; |
96 } |
96 } |
97 else if( TChar(str[n]).IsSpace() ) { |
97 else if( TChar(str[n]).IsSpace() ) { |
98 |
98 |
99 if (indexOfFirstNonRegularSpace==-1) { |
99 if (indexOfFirstNonRegularSpace==-1) { |
100 indexOfFirstNonRegularSpace = n; |
100 indexOfFirstNonRegularSpace = n; |
101 } |
101 } |
102 numSpaces++; |
102 numSpaces++; |
103 if( m_wordSpacing==0 || style.padding()==0 ) { |
103 if( m_wordSpacing==0 || style.padding()==0 ) { |
126 |
126 |
127 // if we have non-regular spaces (nbsp, tab, etc.) we need to make a copy |
127 // if we have non-regular spaces (nbsp, tab, etc.) we need to make a copy |
128 // and replace them with regular spaces. otherwise they show up as boxes. |
128 // and replace them with regular spaces. otherwise they show up as boxes. |
129 if (indexOfFirstNonRegularSpace > -1) { |
129 if (indexOfFirstNonRegularSpace > -1) { |
130 for(; indexOfFirstNonRegularSpace<strLength; ++indexOfFirstNonRegularSpace ) { |
130 for(; indexOfFirstNonRegularSpace<strLength; ++indexOfFirstNonRegularSpace ) { |
131 // if ZERO WIDTH SPACE found do not replace it with regular space |
131 if( TChar(newStr[indexOfFirstNonRegularSpace]).IsSpace()) { |
132 if( TChar(newStr[indexOfFirstNonRegularSpace]).IsSpace() && |
|
133 !(Font::treatAsZeroWidthSpace (newStr[indexOfFirstNonRegularSpace]))) { |
|
134 newStr[indexOfFirstNonRegularSpace] = ' '; |
132 newStr[indexOfFirstNonRegularSpace] = ' '; |
135 } |
133 } |
136 } |
134 } |
137 } |
135 } |
138 |
136 |
139 if (style.rtl()) { |
137 if (style.rtl()) { |
140 TBidiText* bidiText = TBidiText::NewL( newStr, 1, TBidiText::ERightToLeft ); |
138 TBidiText* bidiText = TBidiText::NewL( newStr, 1, TBidiText::ERightToLeft ); |
141 bidiText->WrapText(xForm(width(run)), *font ); |
139 bidiText->WrapText(xForm(width(run)), *font ); |
142 bitgc.DrawText( bidiText->DisplayText(),xForm(startPos)); |
140 bitgc.DrawText( bidiText->DisplayText(),xForm(startPos)); |
143 delete bidiText; |
141 delete bidiText; |
144 } |
142 } |
145 else{ |
143 else{ |
146 bitgc.DrawText( newStr, xForm(startPos) ); |
144 bitgc.DrawText( newStr, xForm(startPos) ); |
147 } |
145 } |
148 |
146 |
149 if (graphicsContext && StaticObjectsContainer::instance()->pictograph()) |
147 if (graphicsContext && StaticObjectsContainer::instance()->pictograph()) |
150 StaticObjectsContainer::instance()->pictograph()->DrawPictographsInText(graphicsContext->platformContext(), bitgc, *font, newStr, startPos ); |
148 StaticObjectsContainer::instance()->pictograph()->DrawPictographsInText(graphicsContext->platformContext(), bitgc, *font, newStr, startPos ); |
151 |
149 |
152 delete text; |
150 delete text; |
153 } |
151 } |
154 |
152 |
155 }else { |
153 }else { |
156 bitgc.DrawText( str, xForm(startPos) ); |
154 bitgc.DrawText( str, xForm(startPos) ); |
157 if (graphicsContext && StaticObjectsContainer::instance()->pictograph()) |
155 if (graphicsContext && StaticObjectsContainer::instance()->pictograph()) |
158 StaticObjectsContainer::instance()->pictograph()->DrawPictographsInText(graphicsContext->platformContext(), bitgc, *font, str, startPos ); |
156 StaticObjectsContainer::instance()->pictograph()->DrawPictographsInText(graphicsContext->platformContext(), bitgc, *font, str, startPos ); |
159 } |
157 } |
160 |
158 |
161 bitgc.DiscardFont(); |
159 bitgc.DiscardFont(); |
162 } |
160 } |
163 |
161 |
164 inline float floatWidthForComplexTextSymbian(const Font* f, const TextRun& run, const TextStyle& style, int maxWidth, int& chars){ |
162 inline float floatWidthForComplexTextSymbian(const Font* f, const TextRun& run, const TextStyle& style, int maxWidth, int& chars){ |
165 const CFont& font( f->primaryFont()->platformData() ); |
163 const CFont& font( f->primaryFont()->platformData() ); |
166 TPtrC str( (const TUint16*)(run.characters()), run.length()); |
164 TPtrC str( (const TUint16*)(run.characters()), run.length()); |
167 |
165 |
168 TInt numSpaces(0); |
166 TInt numSpaces(0); |
169 TInt indexOfFirstNonRegularSpace(-1); |
167 TInt indexOfFirstNonRegularSpace(-1); |
170 TInt strLength(str.Length()); |
168 TInt strLength(str.Length()); |
171 // count the spaces for word spacing |
169 // count the spaces for word spacing |
172 // a) search for nbsp and similar |
170 // a) search for nbsp and similar |