Annotation of /trunk/mozilla-firefox/patches/mozilla-firefox-1.0.7-pango-space-width.patch
Parent Directory | Revision Log
Revision 153 -
(hide annotations)
(download)
Tue May 8 20:52:56 2007 UTC (17 years, 4 months ago) by niro
File size: 4603 byte(s)
Tue May 8 20:52:56 2007 UTC (17 years, 4 months ago) by niro
File size: 4603 byte(s)
-import
1 | niro | 153 | --- mozilla/gfx/src/gtk/nsFontMetricsPango.h.foo 2004-12-10 18:18:18.000000000 -0500 |
2 | +++ mozilla/gfx/src/gtk/nsFontMetricsPango.h 2004-12-10 18:19:16.000000000 -0500 | ||
3 | @@ -256,6 +256,7 @@ | ||
4 | nscoord mMaxDescent; | ||
5 | nscoord mMaxAdvance; | ||
6 | nscoord mSpaceWidth; | ||
7 | + nscoord mPangoSpaceWidth; | ||
8 | nscoord mAveCharWidth; | ||
9 | |||
10 | // Private methods | ||
11 | @@ -282,6 +283,8 @@ | ||
12 | PRInt32& aNumCharsFit, | ||
13 | nsTextDimensions& aLastWordDimensions, | ||
14 | nsRenderingContextGTK *aContext); | ||
15 | + | ||
16 | + void FixupSpaceWidths (PangoLayout *aLayout, const char *aString); | ||
17 | }; | ||
18 | |||
19 | class nsFontEnumeratorPango : public nsIFontEnumerator | ||
20 | --- mozilla/gfx/src/gtk/nsFontMetricsPango.cpp.foo 2004-12-10 18:18:18.000000000 -0500 | ||
21 | +++ mozilla/gfx/src/gtk/nsFontMetricsPango.cpp 2004-12-10 18:19:16.000000000 -0500 | ||
22 | @@ -145,6 +145,7 @@ | ||
23 | mRTLPangoContext = nsnull; | ||
24 | mPangoAttrList = nsnull; | ||
25 | mIsRTL = PR_FALSE; | ||
26 | + mPangoSpaceWidth = 0; | ||
27 | |||
28 | static PRBool initialized = PR_FALSE; | ||
29 | if (initialized) | ||
30 | @@ -345,6 +346,14 @@ | ||
31 | // mMaxAdvance | ||
32 | mMaxAdvance = nscoord(xftFont->max_advance_width * f); | ||
33 | |||
34 | + // mPangoSpaceWidth | ||
35 | + PangoLayout *layout = pango_layout_new(mPangoContext); | ||
36 | + pango_layout_set_text(layout, " ", 1); | ||
37 | + int pswidth, psheight; | ||
38 | + pango_layout_get_size(layout, &pswidth, &psheight); | ||
39 | + mPangoSpaceWidth = pswidth; | ||
40 | + g_object_unref(layout); | ||
41 | + | ||
42 | // mSpaceWidth (width of a space) | ||
43 | nscoord tmpWidth; | ||
44 | GetWidth(" ", 1, tmpWidth, NULL); | ||
45 | @@ -485,6 +494,9 @@ | ||
46 | |||
47 | pango_layout_set_text(layout, aString, aLength); | ||
48 | |||
49 | + if (mPangoSpaceWidth) | ||
50 | + FixupSpaceWidths(layout, aString); | ||
51 | + | ||
52 | int width, height; | ||
53 | |||
54 | pango_layout_get_size(layout, &width, &height); | ||
55 | @@ -526,6 +538,7 @@ | ||
56 | gint width, height; | ||
57 | |||
58 | pango_layout_set_text(layout, text, strlen(text)); | ||
59 | + FixupSpaceWidths(layout, text); | ||
60 | pango_layout_get_size(layout, &width, &height); | ||
61 | |||
62 | width /= PANGO_SCALE; | ||
63 | @@ -573,6 +586,7 @@ | ||
64 | |||
65 | |||
66 | pango_layout_set_text(layout, text, strlen(text)); | ||
67 | + FixupSpaceWidths(layout, text); | ||
68 | |||
69 | // Get the logical extents | ||
70 | PangoLayoutLine *line; | ||
71 | @@ -715,6 +729,7 @@ | ||
72 | PangoLayout *layout = pango_layout_new(mPangoContext); | ||
73 | |||
74 | pango_layout_set_text(layout, aString, aLength); | ||
75 | + FixupSpaceWidths(layout, aString); | ||
76 | |||
77 | int x = aX; | ||
78 | int y = aY; | ||
79 | @@ -778,6 +793,7 @@ | ||
80 | } | ||
81 | |||
82 | pango_layout_set_text(layout, text, strlen(text)); | ||
83 | + FixupSpaceWidths(layout, text); | ||
84 | |||
85 | aContext->GetTranMatrix()->TransformCoord(&x, &y); | ||
86 | |||
87 | @@ -847,6 +863,7 @@ | ||
88 | } | ||
89 | |||
90 | pango_layout_set_text(layout, text, strlen(text)); | ||
91 | + FixupSpaceWidths(layout, text); | ||
92 | |||
93 | // Get the logical extents | ||
94 | PangoLayoutLine *line; | ||
95 | @@ -931,6 +948,7 @@ | ||
96 | |||
97 | // Set up the pango layout | ||
98 | pango_layout_set_text(layout, text, strlen(text)); | ||
99 | + FixupSpaceWidths(layout, text); | ||
100 | |||
101 | // Convert back to UTF-16 while filling in the cluster info | ||
102 | // structure. | ||
103 | @@ -986,6 +1004,7 @@ | ||
104 | |||
105 | // Set up the pango layout | ||
106 | pango_layout_set_text(layout, text, strlen(text)); | ||
107 | + FixupSpaceWidths(layout, text); | ||
108 | |||
109 | found = pango_layout_xy_to_index(layout, localCoord, 0, | ||
110 | &inx, &trailing); | ||
111 | @@ -1087,6 +1106,7 @@ | ||
112 | utf8End = strlen(text); | ||
113 | |||
114 | pango_layout_set_text(layout, text, strlen(text)); | ||
115 | + FixupSpaceWidths(layout, text); | ||
116 | |||
117 | PangoLayoutLine *line; | ||
118 | if (pango_layout_get_line_count(layout) != 1) { | ||
119 | @@ -1502,6 +1522,26 @@ | ||
120 | return NS_OK; | ||
121 | } | ||
122 | |||
123 | +void | ||
124 | +nsFontMetricsPango::FixupSpaceWidths (PangoLayout *aLayout, | ||
125 | + const char *aString) | ||
126 | +{ | ||
127 | + PangoLayoutLine *line = pango_layout_get_line(aLayout, 0); | ||
128 | + | ||
129 | + gint curRun = 0; | ||
130 | + | ||
131 | + for (GSList *tmpList = line->runs; tmpList && tmpList->data; | ||
132 | + tmpList = tmpList->next, curRun++) { | ||
133 | + PangoLayoutRun *layoutRun = (PangoLayoutRun *)tmpList->data; | ||
134 | + | ||
135 | + for (gint i=0; i < layoutRun->glyphs->num_glyphs; i++) { | ||
136 | + gint thisOffset = (gint)layoutRun->glyphs->log_clusters[i] + layoutRun->item->offset; | ||
137 | + if (aString[thisOffset] == ' ') | ||
138 | + layoutRun->glyphs->glyphs[i].geometry.width = mPangoSpaceWidth; | ||
139 | + } | ||
140 | + } | ||
141 | +} | ||
142 | + | ||
143 | /* static */ | ||
144 | PRBool | ||
145 | IsASCIIFontName(const nsString& aName) | ||
146 | @@ -1790,7 +1830,6 @@ | ||
147 | return nsCRT::strcmp(str1, str2); | ||
148 | } | ||
149 | |||
150 | - | ||
151 | // nsFontEnumeratorPango class | ||
152 | |||
153 | nsFontEnumeratorPango::nsFontEnumeratorPango() |