summaryrefslogtreecommitdiffstats
path: root/win/tkWinFont.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tkWinFont.c')
-rw-r--r--win/tkWinFont.c93
1 files changed, 40 insertions, 53 deletions
diff --git a/win/tkWinFont.c b/win/tkWinFont.c
index 7b5e4c9..c01dc3f 100644
--- a/win/tkWinFont.c
+++ b/win/tkWinFont.c
@@ -26,9 +26,9 @@
* Under Windows, a "font family" is uniquely identified by its face name.
*/
-#define FONTMAP_SHIFT 10
+#define FONTMAP_SHIFT 12
-#define FONTMAP_PAGES (1 << (sizeof(Tcl_UniChar)*8 - FONTMAP_SHIFT))
+#define FONTMAP_PAGES (1 << (21 - FONTMAP_SHIFT))
#define FONTMAP_BITSPERPAGE (1 << FONTMAP_SHIFT)
typedef struct FontFamily {
@@ -262,16 +262,7 @@ void
TkpFontPkgInit(
TkMainInfo *mainPtr) /* The application being created. */
{
- if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
- /*
- * If running NT, then we will be calling some Unicode functions
- * explictly. So, even if the Tcl system encoding isn't Unicode, make
- * sure we convert to/from the Unicode char set.
- */
-
- systemEncoding = TkWinGetUnicodeEncoding();
- }
-
+ systemEncoding = TkWinGetUnicodeEncoding();
TkWinSetupSystemFonts(mainPtr);
}
@@ -760,14 +751,14 @@ TkpGetFontAttrsForChar(
* character */
FontFamily *familyPtr = thisSubFontPtr->familyPtr;
HFONT oldfont; /* Saved font from the device context */
- TEXTMETRICA tm; /* Font metrics of the selected subfont */
+ TEXTMETRIC tm; /* Font metrics of the selected subfont */
/*
* Get the font attributes.
*/
oldfont = SelectObject(hdc, thisSubFontPtr->hFont0);
- GetTextMetricsA(hdc, &tm);
+ GetTextMetrics(hdc, &tm);
SelectObject(hdc, oldfont);
ReleaseDC(fontPtr->hwnd, hdc);
faPtr->family = familyPtr->faceName;
@@ -828,7 +819,7 @@ Tk_MeasureChars(
HFONT oldFont;
WinFont *fontPtr;
int curX, moretomeasure;
- Tcl_UniChar ch;
+ int ch;
SIZE size;
FontFamily *familyPtr;
Tcl_DString runString;
@@ -859,7 +850,7 @@ Tk_MeasureChars(
start = source;
end = start + numBytes;
for (p = start; p < end; ) {
- next = p + Tcl_UtfToUniChar(p, &ch);
+ next = p + TkUtfToUniChar(p, &ch);
thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
if (thisSubFontPtr != lastSubFontPtr) {
familyPtr = lastSubFontPtr->familyPtr;
@@ -921,7 +912,7 @@ Tk_MeasureChars(
familyPtr = lastSubFontPtr->familyPtr;
Tcl_DStringInit(&runString);
for (p = start; p < end; ) {
- next = p + Tcl_UtfToUniChar(p, &ch);
+ next = p + TkUtfToUniChar(p, &ch);
Tcl_UtfToExternal(NULL, familyPtr->encoding, p,
(int) (next - p), 0, NULL, buf, sizeof(buf), NULL,
&dstWrote, NULL);
@@ -970,13 +961,13 @@ Tk_MeasureChars(
*/
const char *lastWordBreak = NULL;
- Tcl_UniChar ch2;
+ int ch2;
end = p;
p = source;
ch = ' ';
while (p < end) {
- next = p + Tcl_UtfToUniChar(p, &ch2);
+ next = p + TkUtfToUniChar(p, &ch2);
if ((ch != ' ') && (ch2 == ' ')) {
lastWordBreak = p;
}
@@ -1118,7 +1109,7 @@ Tk_DrawChars(
HBRUSH oldBrush, stipple;
HBITMAP oldBitmap, bitmap;
HDC dcMem;
- TEXTMETRICA tm;
+ TEXTMETRIC tm;
SIZE size;
if (twdPtr->type != TWD_BITMAP) {
@@ -1145,7 +1136,7 @@ Tk_DrawChars(
*/
GetTextExtentPointA(dcMem, source, numBytes, &size);
- GetTextMetricsA(dcMem, &tm);
+ GetTextMetrics(dcMem, &tm);
size.cx -= tm.tmOverhang;
bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
oldBitmap = SelectObject(dcMem, bitmap);
@@ -1184,7 +1175,7 @@ Tk_DrawChars(
} else {
HBITMAP oldBitmap, bitmap;
HDC dcMem;
- TEXTMETRICA tm;
+ TEXTMETRIC tm;
SIZE size;
dcMem = CreateCompatibleDC(dc);
@@ -1199,7 +1190,7 @@ Tk_DrawChars(
*/
GetTextExtentPointA(dcMem, source, numBytes, &size);
- GetTextMetricsA(dcMem, &tm);
+ GetTextMetrics(dcMem, &tm);
size.cx -= tm.tmOverhang;
bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
oldBitmap = SelectObject(dcMem, bitmap);
@@ -1266,7 +1257,7 @@ TkDrawAngledChars(
HBRUSH oldBrush, stipple;
HBITMAP oldBitmap, bitmap;
HDC dcMem;
- TEXTMETRICA tm;
+ TEXTMETRIC tm;
SIZE size;
if (twdPtr->type != TWD_BITMAP) {
@@ -1293,7 +1284,7 @@ TkDrawAngledChars(
*/
GetTextExtentPointA(dcMem, source, numBytes, &size);
- GetTextMetricsA(dcMem, &tm);
+ GetTextMetrics(dcMem, &tm);
size.cx -= tm.tmOverhang;
bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
oldBitmap = SelectObject(dcMem, bitmap);
@@ -1332,7 +1323,7 @@ TkDrawAngledChars(
} else {
HBITMAP oldBitmap, bitmap;
HDC dcMem;
- TEXTMETRICA tm;
+ TEXTMETRIC tm;
SIZE size;
dcMem = CreateCompatibleDC(dc);
@@ -1347,7 +1338,7 @@ TkDrawAngledChars(
*/
GetTextExtentPointA(dcMem, source, numBytes, &size);
- GetTextMetricsA(dcMem, &tm);
+ GetTextMetrics(dcMem, &tm);
size.cx -= tm.tmOverhang;
bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
oldBitmap = SelectObject(dcMem, bitmap);
@@ -1407,9 +1398,13 @@ TkpDrawCharsInContext(
* whole (not just the range) string when
* drawing. */
{
+ int widthUntilStart;
+
(void) numBytes; /*unused*/
+
+ Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
Tk_DrawChars(display, drawable, gc, tkfont, source + rangeStart,
- rangeLength, x, y);
+ rangeLength, x+widthUntilStart, y);
}
/*
@@ -1443,24 +1438,32 @@ MultiFontTextOut(
* string when drawing. */
double angle)
{
- Tcl_UniChar ch;
+ int ch;
SIZE size;
HFONT oldFont;
FontFamily *familyPtr;
Tcl_DString runString;
const char *p, *end, *next;
SubFont *lastSubFontPtr, *thisSubFontPtr;
- TEXTMETRICA tm;
+ TEXTMETRIC tm;
lastSubFontPtr = &fontPtr->subFontArray[0];
oldFont = SelectFont(hdc, fontPtr, lastSubFontPtr, angle);
- GetTextMetricsA(hdc, &tm);
+ GetTextMetrics(hdc, &tm);
end = source + numBytes;
for (p = source; p < end; ) {
- next = p + Tcl_UtfToUniChar(p, &ch);
+ next = p + TkUtfToUniChar(p, &ch);
thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
- if (thisSubFontPtr != lastSubFontPtr) {
+
+ /*
+ * The drawing API has a limit of 32767 pixels in one go.
+ * To avoid spending time on a rare case we do not measure each char,
+ * instead we limit to drawing chunks of 200 bytes since that works
+ * well in practice.
+ */
+
+ if ((thisSubFontPtr != lastSubFontPtr) || (p-source > 200)) {
if (p > source) {
familyPtr = lastSubFontPtr->familyPtr;
Tcl_UtfToExternalDString(familyPtr->encoding, source,
@@ -1478,7 +1481,7 @@ MultiFontTextOut(
lastSubFontPtr = thisSubFontPtr;
source = p;
SelectFont(hdc, fontPtr, lastSubFontPtr, angle);
- GetTextMetricsA(hdc, &tm);
+ GetTextMetrics(hdc, &tm);
}
p = next;
}
@@ -1556,7 +1559,7 @@ InitFont(
HDC hdc;
HWND hwnd;
HFONT oldFont;
- TEXTMETRICA tm;
+ TEXTMETRIC tm;
Window window;
TkFontMetrics *fmPtr;
Tcl_Encoding encoding;
@@ -1569,7 +1572,7 @@ InitFont(
hdc = GetDC(hwnd);
oldFont = SelectObject(hdc, hFont);
- GetTextMetricsA(hdc, &tm);
+ GetTextMetrics(hdc, &tm);
/*
* On any version NT, there may fonts with international names. Use the
@@ -2188,7 +2191,7 @@ FontMapLoadPage(
{
FontFamily *familyPtr;
Tcl_Encoding encoding;
- char src[TCL_UTF_MAX], buf[16];
+ char src[XMaxTransChars], buf[16];
USHORT *startCount, *endCount;
int i, j, bitOffset, end, segCount;
@@ -2525,22 +2528,6 @@ FamilyExists(
int result;
Tcl_DString faceString;
- /*
- * Just immediately rule out the following fonts, because they look so
- * ugly on windows. The caller's fallback mechanism will cause the
- * corresponding appropriate TrueType fonts to be selected.
- */
-
- if (strcasecmp(faceName, "Courier") == 0) {
- return 0;
- }
- if (strcasecmp(faceName, "Times") == 0) {
- return 0;
- }
- if (strcasecmp(faceName, "Helvetica") == 0) {
- return 0;
- }
-
Tcl_UtfToExternalDString(systemEncoding, faceName, -1, &faceString);
/*