… | |
… | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
16 | * |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | *---------------------------------------------------------------------*/ |
20 | *---------------------------------------------------------------------*/ |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
24 | #include "rxvtutil.h" |
24 | #include "rxvtutil.h" |
… | |
… | |
851 | |
851 | |
852 | XCharStruct g; |
852 | XCharStruct g; |
853 | int dir_ret, asc_ret, des_ret; |
853 | int dir_ret, asc_ret, des_ret; |
854 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
854 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
855 | |
855 | |
856 | int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; |
856 | int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
857 | |
857 | |
858 | if (width < g.width) width = g.width; |
858 | if (width < g.width) width = g.width; |
859 | } |
859 | } |
860 | |
860 | |
861 | if (cs == CS_UNKNOWN) |
861 | if (cs == CS_UNKNOWN) |
… | |
… | |
936 | return true; |
936 | return true; |
937 | |
937 | |
938 | // check character against base font bounding box |
938 | // check character against base font bounding box |
939 | int w = xcs->width; |
939 | int w = xcs->width; |
940 | int wcw = wcwidth (unicode); |
940 | int wcw = wcwidth (unicode); |
941 | if (wcw > 0) w /= wcw; |
941 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
942 | |
942 | |
943 | careful = w > prop->width; |
943 | careful = w > prop->width; |
944 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
944 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
945 | return false; |
945 | return false; |
946 | |
946 | |
… | |
… | |
1154 | |
1154 | |
1155 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1155 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1156 | |
1156 | |
1157 | XftUnlockFace (f); |
1157 | XftUnlockFace (f); |
1158 | |
1158 | |
|
|
1159 | int glheight = height; |
|
|
1160 | |
1159 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1161 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1160 | { |
1162 | { |
1161 | FcChar16 ch = *t; |
1163 | FcChar16 ch = *t; |
1162 | |
1164 | |
1163 | if (cs != CS_UNICODE |
1165 | if (cs != CS_UNICODE |
… | |
… | |
1171 | continue; |
1173 | continue; |
1172 | |
1174 | |
1173 | XGlyphInfo g; |
1175 | XGlyphInfo g; |
1174 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1176 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1175 | |
1177 | |
|
|
1178 | g.width -= g.x; |
|
|
1179 | |
1176 | int wcw = wcwidth (ch); |
1180 | int wcw = wcwidth (ch); |
1177 | if (wcw > 0) g.width = g.width / wcw; |
1181 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1178 | |
1182 | |
1179 | if (width < g.width) width = g.width; |
1183 | if (width < g.width ) width = g.width; |
1180 | if (height < g.height) height = g.height; |
1184 | if (height < g.height ) height = g.height; |
|
|
1185 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1186 | } |
|
|
1187 | |
|
|
1188 | if (!width) |
|
|
1189 | { |
|
|
1190 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1191 | |
|
|
1192 | XftFontClose (disp, f); |
|
|
1193 | f = 0; |
|
|
1194 | |
|
|
1195 | success = false; |
|
|
1196 | break; |
1181 | } |
1197 | } |
1182 | |
1198 | |
1183 | if (prop.height == rxvt_fontprop::unset |
1199 | if (prop.height == rxvt_fontprop::unset |
1184 | || height <= prop.height |
1200 | || (height <= prop.height && glheight <= prop.height) |
1185 | || height <= 2 |
1201 | || height <= 2 |
1186 | || !scalable) |
1202 | || !scalable) |
1187 | break; |
1203 | break; |
1188 | |
1204 | |
1189 | if (ftheight) |
1205 | if (ftheight) |
… | |
… | |
1196 | ftheight -= height - prop.height; |
1212 | ftheight -= height - prop.height; |
1197 | } |
1213 | } |
1198 | else |
1214 | else |
1199 | ftheight = prop.height - 1; |
1215 | ftheight = prop.height - 1; |
1200 | |
1216 | |
1201 | XftFontClose (disp, f); |
1217 | XftFontClose (disp, f); |
1202 | FcPatternDel (match, FC_PIXEL_SIZE); |
1218 | FcPatternDel (match, FC_PIXEL_SIZE); |
1203 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1219 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1204 | } |
1220 | } |
1205 | |
1221 | |
1206 | FcPatternDestroy (match); |
1222 | FcPatternDestroy (match); |
1207 | |
1223 | |
1208 | #if 0 // do it per-character |
1224 | #if 0 // do it per-character |
… | |
… | |
1230 | // check character against base font bounding box |
1246 | // check character against base font bounding box |
1231 | FcChar32 ch = unicode; |
1247 | FcChar32 ch = unicode; |
1232 | XGlyphInfo g; |
1248 | XGlyphInfo g; |
1233 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1249 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1234 | |
1250 | |
1235 | int w = g.width; |
1251 | int w = g.width - g.x; |
1236 | int wcw = wcwidth (unicode); |
1252 | int wcw = wcwidth (unicode); |
1237 | if (wcw > 0) w /= wcw; |
1253 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1238 | |
1254 | |
1239 | careful = w > prop->width; |
1255 | careful = w > prop->width; |
1240 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1256 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1241 | return false; |
1257 | return false; |
1242 | |
1258 | |
… | |
… | |
1254 | |
1270 | |
1255 | XGlyphInfo extents; |
1271 | XGlyphInfo extents; |
1256 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1272 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1257 | FcChar32 *ep = enc; |
1273 | FcChar32 *ep = enc; |
1258 | int ewidth = 0; |
1274 | int ewidth = 0; |
1259 | int xoff = 0; |
|
|
1260 | |
1275 | |
1261 | while (len) |
1276 | while (len) |
1262 | { |
1277 | { |
1263 | int cwidth = r->TermWin.fwidth; |
1278 | int cwidth = r->TermWin.fwidth; |
1264 | FcChar32 fc = *text++; len--; |
1279 | FcChar32 fc = *text++; len--; |
1265 | FT_UInt gl; |
|
|
1266 | |
1280 | |
1267 | while (len && *text == NOCHAR) |
1281 | while (len && *text == NOCHAR) |
1268 | text++, len--, cwidth += r->TermWin.fwidth; |
1282 | text++, len--, cwidth += r->TermWin.fwidth; |
1269 | |
1283 | |
1270 | gl = XftCharIndex (d.display->display, f, fc); |
|
|
1271 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1272 | |
|
|
1273 | if (extents.xOff != cwidth && ep != enc) |
|
|
1274 | { |
|
|
1275 | if (xoff > ewidth) xoff = ewidth; |
|
|
1276 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1277 | x + (ewidth - xoff >> 1), |
|
|
1278 | y + base, enc, ep - enc); |
|
|
1279 | x += ewidth; |
|
|
1280 | |
|
|
1281 | ep = enc; |
|
|
1282 | ewidth = 0; |
|
|
1283 | xoff = 0; |
|
|
1284 | } |
|
|
1285 | |
|
|
1286 | if (fc == ' ' && ep == enc) // skip leading spaces |
1284 | if (fc == ' ' && ep == enc) // skip leading spaces |
1287 | { |
|
|
1288 | x += cwidth; |
1285 | x += cwidth; |
1289 | continue; |
|
|
1290 | } |
|
|
1291 | |
|
|
1292 | else |
1286 | else |
1293 | { |
1287 | { |
|
|
1288 | FT_UInt gl = XftCharIndex (d.display->display, f, fc); |
|
|
1289 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1290 | |
|
|
1291 | if (extents.xOff != cwidth) |
|
|
1292 | { |
|
|
1293 | if (ewidth) |
|
|
1294 | { |
|
|
1295 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1296 | x, y + base, enc, ep - enc); |
|
|
1297 | x += ewidth; |
|
|
1298 | |
|
|
1299 | ep = enc; |
|
|
1300 | ewidth = 0; |
|
|
1301 | } |
|
|
1302 | |
|
|
1303 | if (extents.xOff > cwidth) |
|
|
1304 | extents.xOff = cwidth; |
|
|
1305 | |
|
|
1306 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1307 | x + (cwidth - extents.xOff >> 1), |
|
|
1308 | y + base, &gl, 1); |
|
|
1309 | x += cwidth; |
|
|
1310 | } |
|
|
1311 | else |
|
|
1312 | { |
1294 | *ep++ = gl; |
1313 | *ep++ = gl; |
1295 | ewidth += cwidth; |
1314 | ewidth += cwidth; |
1296 | xoff += extents.xOff; |
1315 | } |
1297 | } |
1316 | } |
1298 | } |
1317 | } |
1299 | |
1318 | |
1300 | if (ep != enc) |
1319 | if (ep != enc) |
1301 | { |
|
|
1302 | if (xoff > ewidth) xoff = ewidth; |
|
|
1303 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1320 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1304 | x + (ewidth - xoff >> 1), |
|
|
1305 | y + base, enc, ep - enc); |
1321 | x, y + base, enc, ep - enc); |
1306 | } |
|
|
1307 | } |
1322 | } |
1308 | #endif |
1323 | #endif |
1309 | |
1324 | |
1310 | ///////////////////////////////////////////////////////////////////////////// |
1325 | ///////////////////////////////////////////////////////////////////////////// |
1311 | |
1326 | |
1312 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1327 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1313 | : r (r), fontdesc (0) |
1328 | : fontdesc (0), r (r) |
1314 | { |
1329 | { |
1315 | clear (); |
1330 | clear (); |
1316 | } |
1331 | } |
1317 | |
1332 | |
1318 | rxvt_fontset::~rxvt_fontset () |
1333 | rxvt_fontset::~rxvt_fontset () |