summaryrefslogtreecommitdiff
path: root/firefox-1.5-xft-rangewidth.patch
blob: 1ecc5f23acfa1fc6d6136886ae3e4a87d083c0f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
diff -pruN -x '.moz*' -x .libs -x .deps -x dist -x 'config*' -x 'firefox*' -x '*a' -x '*so' -x '*o' -x build -x '*html' mozilla.orig/gfx/src/gtk/nsFontMetricsXft.cpp mozilla/gfx/src/gtk/nsFontMetricsXft.cpp
--- mozilla.orig/gfx/src/gtk/nsFontMetricsXft.cpp	2006-04-25 08:58:36.000000000 +0900
+++ mozilla/gfx/src/gtk/nsFontMetricsXft.cpp	2007-02-08 01:50:05.000000000 +0900
@@ -227,10 +227,14 @@ static nsresult EnumFontsXft     (nsIAto
 
 static        void ConvertCharToUCS4    (const char *aString,
                                          PRUint32 aLength,
+                                         PRUint32 aStart,
+                                         PRUint32 aEnd,
                                          nsAutoFcChar32Buffer &aOutBuffer,
                                          PRUint32 *aOutLen);
 static        void ConvertUnicharToUCS4 (const PRUnichar *aString,
                                          PRUint32 aLength,
+                                         PRUint32 aStart,
+                                         PRUint32 aEnd,
                                          nsAutoFcChar32Buffer &aOutBuffer,
                                          PRUint32 *aOutLen);
 static    nsresult ConvertUCS4ToCustom  (FcChar32 *aSrc, PRUint32 aSrcLen,
@@ -507,7 +511,7 @@ nsFontMetricsXft::GetWidth(const PRUnich
         return NS_OK;
     }
 
-    gint rawWidth = RawGetWidth(aString, aLength);
+    gint rawWidth = RawGetWidth(aString, aLength, 0, aLength);
 
     float f;
     f = mDeviceContext->DevUnitsToAppUnits();
@@ -533,7 +537,7 @@ nsFontMetricsXft::GetTextDimensions(cons
         return NS_OK;
 
     nsresult rv;
-    rv = EnumerateGlyphs(aString, aLength,
+    rv = EnumerateGlyphs(aString, aLength, 0, aLength,
                          &nsFontMetricsXft::TextDimensionsCallback,
                          &aDimensions);
 
@@ -608,7 +612,7 @@ nsFontMetricsXft::DrawString(const char 
     nsAutoDrawSpecBuffer drawBuffer(data.draw, &data.color);
     data.drawBuffer = &drawBuffer;
 
-    return EnumerateGlyphs(aString, aLength,
+    return EnumerateGlyphs(aString, aLength, 0, aLength,
                            &nsFontMetricsXft::DrawStringCallback, &data);
 }
 
@@ -638,7 +642,7 @@ nsFontMetricsXft::DrawString(const PRUni
     nsAutoDrawSpecBuffer drawBuffer(data.draw, &data.color);
     data.drawBuffer = &drawBuffer;
 
-    return EnumerateGlyphs(aString, aLength,
+    return EnumerateGlyphs(aString, aLength, 0, aLength,
                            &nsFontMetricsXft::DrawStringCallback, &data);
 }
 
@@ -662,7 +666,7 @@ nsFontMetricsXft::GetBoundingMetrics(con
     data.firstTime = PR_TRUE; 
 
     nsresult rv;
-    rv = EnumerateGlyphs(aString, aLength,
+    rv = EnumerateGlyphs(aString, aLength, 0, aLength,
                          &nsFontMetricsXft::BoundingMetricsCallback, &data);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -700,7 +704,7 @@ nsFontMetricsXft::GetBoundingMetrics(con
     data.firstTime = PR_TRUE; 
 
     nsresult rv;
-    rv = EnumerateGlyphs(aString, aLength,
+    rv = EnumerateGlyphs(aString, aLength, 0, aLength,
                          &nsFontMetricsXft::BoundingMetricsCallback, &data);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -758,7 +762,17 @@ nsFontMetricsXft::GetRangeWidth(const PR
                                 PRUint32 aEnd,
                                 PRUint32 &aWidth)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+    if (!aLength) {
+        aWidth = 0;
+        return NS_OK;
+    }
+
+    gint rawWidth = RawGetWidth(aText, aLength, aStart, aEnd);
+    float f = mDeviceContext->DevUnitsToAppUnits();
+
+    aWidth = NSToCoordRound(rawWidth * f);
+
+    return NS_OK;
 }
 
 nsresult
@@ -768,7 +782,17 @@ nsFontMetricsXft::GetRangeWidth(const ch
                                 PRUint32 aEnd,
                                 PRUint32 &aWidth)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+    if (!aLength) {
+        aWidth = 0;
+        return NS_OK;
+    }
+
+    gint rawWidth = RawGetWidth(aText, aLength, aStart, aEnd);
+    float f = mDeviceContext->DevUnitsToAppUnits();
+
+    aWidth = NSToCoordRound(rawWidth * f);
+
+    return NS_OK;
 }
 
 PRUint32
@@ -850,12 +874,12 @@ nsFontMetricsXft::CacheFontMetrics(void)
     // mSpaceWidth (width of a space)
     gint rawWidth;
     PRUnichar unispace(' ');
-    rawWidth = RawGetWidth(&unispace, 1);
+    rawWidth = RawGetWidth(&unispace, 1, 0, 1);
     mSpaceWidth = NSToCoordRound(rawWidth * f);
 
     // mAveCharWidth (width of an 'average' char)
     PRUnichar xUnichar('x');
-    rawWidth = RawGetWidth(&xUnichar, 1);
+    rawWidth = RawGetWidth(&xUnichar, 1, 0, 1);
     mAveCharWidth = NSToCoordRound(rawWidth * f);
 
     // mXHeight (height of an 'x' character)
@@ -1226,12 +1250,27 @@ nsFontMetricsXft::DoMatch(PRBool aMatchA
 }
 
 gint
-nsFontMetricsXft::RawGetWidth(const PRUnichar* aString, PRUint32 aLength)
+nsFontMetricsXft::RawGetWidth(const PRUnichar* aString, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd)
+{
+    nscoord width = 0;
+    nsresult rv;
+
+    rv = EnumerateGlyphs(aString, aLength, aStart, aEnd,
+                         &nsFontMetricsXft::GetWidthCallback, &width);
+
+    if (NS_FAILED(rv))
+        width = 0;
+
+    return width;
+}
+
+gint
+nsFontMetricsXft::RawGetWidth(const char* aString, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd)
 {
     nscoord width = 0;
     nsresult rv;
 
-    rv = EnumerateGlyphs(aString, aLength,
+    rv = EnumerateGlyphs(aString, aLength, aStart, aEnd,
                          &nsFontMetricsXft::GetWidthCallback, &width);
 
     if (NS_FAILED(rv))
@@ -1457,6 +1496,8 @@ nsFontMetricsXft::EnumerateXftGlyphs(con
 nsresult
 nsFontMetricsXft::EnumerateGlyphs(const PRUnichar *aString,
                                   PRUint32 aLen,
+                                  PRUint32 aStart,
+                                  PRUint32 aEnd,
                                   GlyphEnumeratorCallback aCallback,
                                   void *aCallbackData)
 {
@@ -1465,7 +1506,7 @@ nsFontMetricsXft::EnumerateGlyphs(const 
 
     NS_ENSURE_TRUE(aLen, NS_OK); 
 
-    ConvertUnicharToUCS4(aString, aLen, charBuffer, &len);
+    ConvertUnicharToUCS4(aString, aLen, aStart, aEnd, charBuffer, &len);
     if (!len)
         return NS_ERROR_OUT_OF_MEMORY;
 
@@ -1475,6 +1516,8 @@ nsFontMetricsXft::EnumerateGlyphs(const 
 nsresult
 nsFontMetricsXft::EnumerateGlyphs(const char *aString,
                                   PRUint32 aLen,
+                                  PRUint32 aStart,
+                                  PRUint32 aEnd,
                                   GlyphEnumeratorCallback aCallback,
                                   void *aCallbackData)
 {
@@ -1484,7 +1527,7 @@ nsFontMetricsXft::EnumerateGlyphs(const 
     NS_ENSURE_TRUE(aLen, NS_OK); 
 
     // Convert the incoming string into an array of UCS4 chars
-    ConvertCharToUCS4(aString, aLen, charBuffer, &len);
+    ConvertCharToUCS4(aString, aLen, aStart, aEnd, charBuffer, &len);
     if (!len)
         return NS_ERROR_OUT_OF_MEMORY;
 
@@ -2343,7 +2386,7 @@ EnumFontsXft(nsIAtom* aLangGroup, const 
 
 /* static */
 void
-ConvertCharToUCS4(const char *aString, PRUint32 aLength, 
+ConvertCharToUCS4(const char *aString, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd,
                   nsAutoFcChar32Buffer &aOutBuffer, PRUint32 *aOutLen)
 {
     *aOutLen = 0;
@@ -2352,19 +2395,21 @@ ConvertCharToUCS4(const char *aString, P
     if (!aOutBuffer.EnsureElemCapacity(aLength))
         return;
     outBuffer  = aOutBuffer.get();
+    if (aEnd > aLength)
+        aEnd = aLength;
     
-    for (PRUint32 i = 0; i < aLength; ++i) {
-        outBuffer[i] = PRUint8(aString[i]); // to convert char >= 0x80 correctly
+    for (PRUint32 i = aStart; i < aLength && i < aEnd; ++i) {
+        outBuffer[i - aStart] = PRUint8(aString[i]); // to convert char >= 0x80 correctly
     }
 
-    *aOutLen = aLength;
+    *aOutLen = aEnd - aStart;
 }
 
 // Convert the incoming string into an array of UCS4 chars
   
 /* static */
 void
-ConvertUnicharToUCS4(const PRUnichar *aString, PRUint32 aLength,
+ConvertUnicharToUCS4(const PRUnichar *aString, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd,
                      nsAutoFcChar32Buffer &aOutBuffer, PRUint32 *aOutLen)
 {
     *aOutLen = 0;
@@ -2378,7 +2423,7 @@ ConvertUnicharToUCS4(const PRUnichar *aS
 
     // Walk the passed in string looking for surrogates to convert to
     // their full ucs4 representation.
-    for (PRUint32 i = 0; i < aLength; ++i) {
+    for (PRUint32 i = aStart; i < aLength && i < aEnd; ++i) {
         PRUnichar c = aString[i];
 
         // Optimized for the non-surrogate case
@@ -2693,12 +2738,12 @@ ConvertUCS4ToCustom(FcChar32 *aSrc,  PRU
 #endif
         // Convert 16bit  custom font codes to UCS4
         ConvertUnicharToUCS4(NS_REINTERPRET_CAST(PRUnichar *, med),
-                             medLen >> 1, aResult, &aDestLen);
+                             medLen >> 1, 0, medLen >> 1, aResult, &aDestLen);
         rv = aDestLen ? rv : NS_ERROR_OUT_OF_MEMORY;
     }
     else {
         // Convert 8bit custom font codes to UCS4
-        ConvertCharToUCS4(med, medLen, aResult, &aDestLen);
+        ConvertCharToUCS4(med, medLen, 0, medLen, aResult, &aDestLen);
         rv = aDestLen ? rv : NS_ERROR_OUT_OF_MEMORY;
     }
 
diff -pruN -x '.moz*' -x .libs -x .deps -x dist -x 'config*' -x 'firefox*' -x '*a' -x '*so' -x '*o' -x build -x '*html' mozilla.orig/gfx/src/gtk/nsFontMetricsXft.h mozilla/gfx/src/gtk/nsFontMetricsXft.h
--- mozilla.orig/gfx/src/gtk/nsFontMetricsXft.h	2005-05-03 05:48:30.000000000 +0900
+++ mozilla/gfx/src/gtk/nsFontMetricsXft.h	2007-02-08 01:38:27.000000000 +0900
@@ -259,7 +259,13 @@ private:
     void        DoMatch            (PRBool aMatchAll);
 
     gint        RawGetWidth        (const PRUnichar* aString,
-                                    PRUint32         aLength);
+                                    PRUint32         aLength,
+                                    PRUint32         aStart,
+                                    PRUint32         aEnd);
+    gint        RawGetWidth        (const char* aString,
+                                    PRUint32    aLength,
+                                    PRUint32    aStart,
+                                    PRUint32    aEnd);
     nsresult    SetupMiniFont      (void);
     nsresult    DrawUnknownGlyph   (FcChar32   aChar,
                                     nscoord    aX,
@@ -272,10 +278,14 @@ private:
                                     void     *aCallbackData);
     nsresult    EnumerateGlyphs    (const char *aString,
                                     PRUint32  aLen,
+                                    PRUint32  aStart,
+                                    PRUint32  aEnd,
                                     GlyphEnumeratorCallback aCallback,
                                     void     *aCallbackData);
     nsresult    EnumerateGlyphs    (const PRUnichar *aString,
                                     PRUint32  aLen,
+                                    PRUint32  aStart,
+                                    PRUint32  aEnd,
                                     GlyphEnumeratorCallback aCallback,
                                     void     *aCallbackData);
     void        PrepareToDraw      (nsRenderingContextGTK *aContext,
bgstack15