summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXFont.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2012-02-22 22:58:19 (GMT)
committerKevin Walzer <kw@codebykevin.com>2012-02-22 22:58:19 (GMT)
commit9c889def7246e422c1eb98aa2e5e9e7e66298d44 (patch)
treede7ac26bd91d800ecba2dca0aa0539a1a44b20d3 /macosx/tkMacOSXFont.c
parent57b1224d0740ffbd5208457481ca421450bd6748 (diff)
downloadtk-9c889def7246e422c1eb98aa2e5e9e7e66298d44.zip
tk-9c889def7246e422c1eb98aa2e5e9e7e66298d44.tar.gz
tk-9c889def7246e422c1eb98aa2e5e9e7e66298d44.tar.bz2
Patch for font metrics and colorspace provided by Adrian Robert
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r--macosx/tkMacOSXFont.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 305fe53..e4e4e03 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -229,7 +229,7 @@ InitFont(
NSRect bounds;
CGFloat kern = 0.0;
NSFontRenderingMode renderingMode = NSFontDefaultRenderingMode;
- int ascent, descent, dontAA;
+ int ascent, descent/*, dontAA*/;
static const UniChar ch[] = {'.', 'W', ' ', 0xc4, 0xc1, 0xc2, 0xc3, 0xc7};
/* ., W, Space, Auml, Aacute, Acirc, Atilde, Ccedilla */
#define nCh (sizeof(ch) / sizeof(UniChar))
@@ -244,9 +244,10 @@ InitFont(
TkInitFontAttributes(faPtr);
}
fontPtr->nsFont = nsFont;
- dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10;
- if (antialiasedTextEnabled >= 0 || dontAA) {
- renderingMode = (antialiasedTextEnabled == 0 || dontAA) ?
+ // some don't like antialiasing on fixed-width even if bigger than limit
+// dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10;
+ if (antialiasedTextEnabled >= 0/* || dontAA*/) {
+ renderingMode = (antialiasedTextEnabled == 0/* || dontAA*/) ?
NSFontIntegerAdvancementsRenderingMode :
NSFontAntialiasedRenderingMode;
}
@@ -828,7 +829,7 @@ TkpMeasureCharsInContext(
typesetter = CTTypesetterCreateWithAttributedString(
(CFAttributedStringRef)attributedString);
start = Tcl_NumUtfChars(source, rangeStart);
- len = Tcl_NumUtfChars(source, rangeStart + rangeLength);
+ len = Tcl_NumUtfChars(source + rangeStart, rangeLength);
if (start > 0) {
range.length = start;
line = CTTypesetterCreateLine(typesetter, range);
@@ -847,13 +848,13 @@ TkpMeasureCharsInContext(
index = start;
if (flags & TK_WHOLE_WORDS) {
- index = CTTypesetterSuggestLineBreak(typesetter, 0, maxWidth);
+ index = CTTypesetterSuggestLineBreak(typesetter, start, maxWidth);
if (index <= start && (flags & TK_AT_LEAST_ONE)) {
flags &= ~TK_WHOLE_WORDS;
}
}
if (index <= start && !(flags & TK_WHOLE_WORDS)) {
- index = CTTypesetterSuggestClusterBreak(typesetter, 0, maxWidth);
+ index = CTTypesetterSuggestClusterBreak(typesetter, start, maxWidth);
}
cs = (index < len || (flags & TK_WHOLE_WORDS)) ?
whitespaceCharacterSet : lineendingCharacterSet;
@@ -878,6 +879,17 @@ TkpMeasureCharsInContext(
width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
CFRelease(line);
}
+
+ /* The call to CTTypesetterSuggestClusterBreak above will always
+ return at least one character regardless of whether it exceeded
+ it or not. Clean that up now. */
+ while (width > maxWidth && !(flags & TK_PARTIAL_OK) && index > start) {
+ range.length = --index;
+ line = CTTypesetterCreateLine(typesetter, range);
+ width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
+ CFRelease(line);
+ }
+
}
CFRelease(typesetter);
[attributedString release];
@@ -894,6 +906,7 @@ done:
flags & TK_AT_LEAST_ONE ? "atLeastOne " : "",
flags & TK_ISOLATE_END ? "isolateEnd " : "",
length, fit);
+//if (!(rangeLength==1 && rangeStart == 0)) fprintf(stderr, " measure len=%d (max=%d, w=%.0f) from %d (nb=%d): source=\"%s\": index=%d return %d\n",rangeLength,maxLength,width,rangeStart,numBytes, source+rangeStart, index, fit);
#endif
*lengthPtr = length;
return fit;