comparison src/w32term.c @ 31624:417b6743c5fa

(w32_per_char_metric): Handle non-TrueType fonts.
author Andrew Innes <andrewi@gnu.org>
date Thu, 14 Sep 2000 21:34:22 +0000
parents bbd7763673b6
children 1f26caa05cd7
comparison
equal deleted inserted replaced
31623:803eb50a2405 31624:417b6743c5fa
1138 wchar_t *char2b; 1138 wchar_t *char2b;
1139 enum w32_char_font_type font_type; 1139 enum w32_char_font_type font_type;
1140 { 1140 {
1141 /* The result metric information. */ 1141 /* The result metric information. */
1142 XCharStruct *pcm; 1142 XCharStruct *pcm;
1143 ABC char_widths;
1144 SIZE sz;
1145 BOOL retval; 1143 BOOL retval;
1146 1144
1147 xassert (font && char2b); 1145 xassert (font && char2b);
1148 1146
1149 if (font_type == UNKNOWN_FONT) 1147 if (font_type == UNKNOWN_FONT)
1159 pcm = (XCharStruct *) xmalloc (sizeof (XCharStruct)); 1157 pcm = (XCharStruct *) xmalloc (sizeof (XCharStruct));
1160 1158
1161 if (font->hfont) 1159 if (font->hfont)
1162 SelectObject (hdc, font->hfont); 1160 SelectObject (hdc, font->hfont);
1163 1161
1164 if (font_type == UNICODE_FONT) 1162 if ((font->tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0)
1165 retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths); 1163 {
1166 else if (font_type == ANSI_FONT) 1164 ABC char_widths;
1167 retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths); 1165
1168 1166 if (font_type == UNICODE_FONT)
1169 if (retval) 1167 retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths);
1170 { 1168 else if (font_type == ANSI_FONT)
1171 pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC; 1169 retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths);
1172 pcm->lbearing = char_widths.abcA; 1170
1173 pcm->rbearing = pcm->width - char_widths.abcC; 1171 if (retval)
1172 {
1173 pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC;
1174 pcm->lbearing = char_widths.abcA;
1175 pcm->rbearing = pcm->width - char_widths.abcC;
1176 }
1177 else
1178 {
1179 /* Windows 9x does not implement GetCharABCWidthsW, so if that
1180 failed, try GetTextExtentPoint32W, which is implemented and
1181 at least gives us some of the info we are after (total
1182 character width). */
1183 SIZE sz;
1184
1185 if (font_type == UNICODE_FONT)
1186 retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz);
1187
1188 if (retval)
1189 {
1190 pcm->width = sz.cx;
1191 pcm->rbearing = sz.cx;
1192 pcm->lbearing = 0;
1193 }
1194 else
1195 {
1196 xfree (pcm);
1197 return NULL;
1198 }
1199 }
1174 } 1200 }
1175 else 1201 else
1176 { 1202 {
1177 /* Windows 9x does not implement GetCharABCWidthsW, so if that 1203 /* Do our best to deduce the desired metrics data for non-Truetype
1178 failed, try GetTextExtentPoint32W, which is implemented and 1204 fonts (generally, raster fonts). */
1179 at least gives us some of the info we are after (total 1205 INT char_width;
1180 character width). */ 1206
1181 if (font_type == UNICODE_FONT) 1207 retval = GetCharWidth (hdc, *char2b, *char2b, &char_width);
1182 retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz);
1183
1184 if (retval) 1208 if (retval)
1185 { 1209 {
1186 pcm->width = sz.cx; 1210 pcm->width = char_width;
1187 pcm->rbearing = sz.cx; 1211 pcm->rbearing = char_width;
1188 pcm->lbearing = 0; 1212 pcm->lbearing = 0;
1189 } 1213 }
1190 else 1214 else
1191 { 1215 {
1192 xfree (pcm); 1216 xfree (pcm);
1193 return NULL; 1217 return NULL;
1194 } 1218 }
1195 } 1219 }
1196 1220
1197 pcm->ascent = FONT_BASE (font); 1221 pcm->ascent = FONT_BASE (font);
1198 pcm->descent = FONT_DESCENT (font); 1222 pcm->descent = FONT_DESCENT (font);
1199 1223