summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXFont.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r--macosx/tkMacOSXFont.c96
1 files changed, 85 insertions, 11 deletions
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index f5f93b4..d800ae5 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -10,8 +10,6 @@
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id$
*/
#include "tkMacOSXPrivate.h"
@@ -93,9 +91,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 -
@@ -454,7 +452,7 @@ TkpGetNativeFont(
ctFont = CTFontCreateUIFontForLanguage(HIThemeGetUIFontType(
themeFontId), 0, NULL);
if (ctFont) {
- fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
+ fontPtr = ckalloc(sizeof(MacFont));
InitFont((NSFont*) ctFont, NULL, fontPtr);
}
@@ -510,7 +508,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);
@@ -523,7 +521,7 @@ TkpGetFontFromAttributes(
Tcl_Panic("Could not deternmine NSFont from TkFontAttributes");
}
if (tkFontPtr == NULL) {
- fontPtr = (MacFont *) ckalloc(sizeof(MacFont));
+ fontPtr = ckalloc(sizeof(MacFont));
} else {
fontPtr = (MacFont *) tkFontPtr;
TkpDeleteFont(tkFontPtr);
@@ -885,7 +883,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);
@@ -955,6 +954,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);
+}
+
/*
*---------------------------------------------------------------------------
*
@@ -1067,7 +1089,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);
@@ -1168,6 +1190,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
@@ -1216,7 +1290,7 @@ TkMacOSXUseAntialiasedText(
/*
* Local Variables:
- * mode: c
+ * mode: objc
* c-basic-offset: 4
* fill-column: 79
* coding: utf-8