diff options
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r-- | macosx/tkMacOSXFont.c | 92 |
1 files changed, 84 insertions, 8 deletions
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index f329071..c48e56e 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -104,9 +104,9 @@ static void DrawCharsInContext(Display *display, Drawable drawable, GC gc, int rangeLength, int x, int y, double angle); @interface NSFont(TKFont) -- (NSFont *)bestMatchingFontForCharacters:(const UTF16Char *)characters - length:(NSUInteger)length attributes:(NSDictionary *)attributes - actualCoveredLength:(NSUInteger *)coveredLength; +- (NSFont *) bestMatchingFontForCharacters: (const UTF16Char *) characters + length: (NSUInteger) length attributes: (NSDictionary *) attributes + actualCoveredLength: (NSUInteger *) coveredLength; @end #pragma mark - @@ -466,7 +466,7 @@ TkpGetNativeFont( ctFont = CTFontCreateUIFontForLanguage(HIThemeGetUIFontType( themeFontId), 0, NULL); if (ctFont) { - fontPtr = (MacFont *) ckalloc(sizeof(MacFont)); + fontPtr = ckalloc(sizeof(MacFont)); InitFont((NSFont*) ctFont, NULL, fontPtr); } @@ -522,7 +522,7 @@ TkpGetFontFromAttributes( nsFont = FindNSFont(faPtr->family, traits, weight, points, 0); if (!nsFont) { - char *const *aliases = TkFontGetAliasList(faPtr->family); + const char *const *aliases = TkFontGetAliasList(faPtr->family); while (aliases && !nsFont) { nsFont = FindNSFont(*aliases++, traits, weight, points, 0); @@ -535,7 +535,7 @@ TkpGetFontFromAttributes( Tcl_Panic("Could not determine NSFont from TkFontAttributes"); } if (tkFontPtr == NULL) { - fontPtr = (MacFont *) ckalloc(sizeof(MacFont)); + fontPtr = ckalloc(sizeof(MacFont)); } else { fontPtr = (MacFont *) tkFontPtr; TkpDeleteFont(tkFontPtr); @@ -897,7 +897,8 @@ TkpMeasureCharsInContext( /* 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+(flags & TK_AT_LEAST_ONE)) { + while (width > maxWidth && !(flags & TK_PARTIAL_OK) + && index > start+(flags & TK_AT_LEAST_ONE)) { range.length = --index; line = CTTypesetterCreateLine(typesetter, range); width = CTLineGetTypographicBounds(line, NULL, NULL, NULL); @@ -967,6 +968,29 @@ Tk_DrawChars( 0, numBytes, x, y, 0.0); } +void +TkDrawAngledChars( + Display *display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context for drawing characters. */ + Tk_Font tkfont, /* Font in which characters will be drawn; + * must be the same as font used in GC. */ + const char *source, /* UTF-8 string to be displayed. Need not be + * '\0' terminated. All Tk meta-characters + * (tabs, control characters, and newlines) + * should be stripped out of the string that + * is passed to this function. If they are not + * stripped out, they will be displayed as + * regular printing characters. */ + int numBytes, /* Number of bytes in string. */ + double x, double y, /* Coordinates at which to place origin of + * string when drawing. */ + double angle) /* What angle to put text at, in degrees. */ +{ + DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes, + 0, numBytes, x, y, angle); +} + /* *--------------------------------------------------------------------------- * @@ -1079,7 +1103,7 @@ DrawCharsInContext( t = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, h); if (angle != 0.0) { t = CGAffineTransformTranslate(CGAffineTransformRotate( - CGAffineTransformTranslate(t, x, y), angle*M_PI/180.0), -x, -y); + CGAffineTransformTranslate(t, x, y), angle*PI/180.0), -x, -y); } CGContextConcatCTM(context, t); CGContextSetTextPosition(context, x, y); @@ -1180,6 +1204,58 @@ TkMacOSXIsCharacterMissing( /* *---------------------------------------------------------------------- * + * TkMacOSXFontDescriptionForNSFontAndNSFontAttributes -- + * + * Get text description of a font specified by NSFont and attributes. + * + * Results: + * List object or NULL. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +MODULE_SCOPE Tcl_Obj * +TkMacOSXFontDescriptionForNSFontAndNSFontAttributes( + NSFont *nsFont, + NSDictionary *nsAttributes) +{ + Tcl_Obj *objv[6]; + int i = 0; + const char *familyName = [[nsFont familyName] UTF8String]; + + if (nsFont && familyName) { + NSFontTraitMask traits = [[NSFontManager sharedFontManager] + traitsOfFont:nsFont]; + id underline = [nsAttributes objectForKey: + NSUnderlineStyleAttributeName]; + id strikethrough = [nsAttributes objectForKey: + NSStrikethroughStyleAttributeName]; + objv[i++] = Tcl_NewStringObj(familyName, -1); + objv[i++] = Tcl_NewIntObj([nsFont pointSize]); +#define S(s) Tcl_NewStringObj(STRINGIFY(s),(int)(sizeof(STRINGIFY(s))-1)) + objv[i++] = (traits & NSBoldFontMask) ? S(bold) : S(normal); + objv[i++] = (traits & NSItalicFontMask) ? S(italic) : S(roman); + if ([underline respondsToSelector:@selector(intValue)] && + ([underline intValue] & (NSUnderlineStyleSingle | + NSUnderlineStyleThick | NSUnderlineStyleDouble))) { + objv[i++] = S(underline); + } + if ([strikethrough respondsToSelector:@selector(intValue)] && + ([strikethrough intValue] & (NSUnderlineStyleSingle | + NSUnderlineStyleThick | NSUnderlineStyleDouble))) { + objv[i++] = S(overstrike); + } +#undef S + } + return i ? Tcl_NewListObj(i, objv) : NULL; +} + +/* + *---------------------------------------------------------------------- + * * TkMacOSXUseAntialiasedText -- * * Enables or disables application-wide use of antialiased text (where |