Quartz ã§ãæ¥æ¬èª font ã使ããã on iPhone
CGFontGetGlyphsForUnichars ã«ä»£ããé¢æ°ãå¼ã³åºããå®è£ ãç¨æããããã¨ãã話ã§ãã
æè¿ iPhone ã¢ããªéçºã«ã¯ã¾ã£ã¦ããã®ã§ãããiPhone ã®ãé«é㪠2D æç»æ©è½ã§ãã Quartz ã§æ¥æ¬èªã使ãã®ã«è¦å´ããã®ã§æ¸ãæ®ãã¦ããã¾ãã
Quartz 㯠Mac åãã® OSX ã§ãæ¡ç¨ããã¦ãããPDF ã®æä½ãªã©ãåºæ¥ãé«é㪠æç»ãã¬ã¼ã ã¯ã¼ã¯ã§ããObjectice-C ããå¼ã³åºãã¾ãããåºæ¬çã«ã¯ C ã®é¢æ°ãå¼ã³åºãã¦ä½¿ãããã§ãã
ä¾ã«ãã£ã¦ Apple ã®ããã¥ã¡ã³ããç´ æ´ãããã¾ã¨ã¾ã£ã¦ãããWebããé²è¦§åºæ¥ã¾ãã
ãã®è³æã«ããText ã¨ããç« ããã£ã¦æ¬¡ã®ãããªã³ã¼ãã§æåã®æç»ã§ããã¨ããã¾ãã
void MyDrawText (CGContextRef myContext, CGRect contextRect) // 1 { float w, h; w = contextRect.size.width; h = contextRect.size.height; CGAffineTransform myTextTransform; // 2 CGContextSelectFont (myContext, // 3 "Helvetica-Bold", h/10, kCGEncodingMacRoman); CGContextSetCharacterSpacing (myContext, 10); // 4 CGContextSetTextDrawingMode (myContext, kCGTextFillStroke); // 5 CGContextSetRGBFillColor (myContext, 0, 1, 0, .5); // 6 CGContextSetRGBStrokeColor (myContext, 0, 0, 1, 1); // 7 myTextTransform = CGAffineTransformMakeRotation (MyRadians (45)); // 8 CGContextSetTextMatrix (myContext, myTextTransform); // 9 CGContextShowTextAtPoint (myContext, 40, 0, "Quartz 2D", 9); // 10 }
ä¸è¨è³æããå¼ç¨ãã¦ãã¾ãã
æååãMacRomanã§ã³ã¼ãã£ã³ã°ããã¦ããã°ããã§è¯ãã®ã§ãããæ¥æ¬èªã®å ´åã¯ãã¾ãããã¾ããããã©ã³ãæå®ã®
CGContextSelectFont (myContext, // 3 "Helvetica-Bold", h/10, kCGEncodingMacRoman);
ããããã使ããªãã¨è³æã«ã¯æãã¾ããã§ãã©ããããã¨ããã¨ãSelectFontã«å¤ãã¦æ¬¡ã®é¢æ°ã使ãã¾ãã
CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"HiraKakuProN-W3");
CGContextSetFont(myContext, font);
CGContextSetFontSize(myContext, fontSize);
ããã«ãæååæç»ã®é¢æ°ã¯ãCGContextShowTextAtPoint ã使ããªããªãã®ã§ã
void CGContextShowGlyphsAtPoint ( CGContextRef c, CGFloat x, CGFloat y, const CGGlyph glyphs[], size_t count );
ãå©ç¨ãã¾ããããããã§åé¡ã«ãªãã®ããCGGlyph ã§ãã CGGlyph ã¯æåã®å é¨è¡¨ç¾ã§ãæåãã¨ã«å¤ã®æ±ºã¾ã£ã¦ãã unsigned short ã®æ°å¤ã§ããæåãã¨ã«æ±ºã¾ã£ã¦ããå¤ãªã®ã§ããããã©ã³ã種é¡ãã¨ã«éãå¤ãæå®ããã¦ããã®ã§ã©ãã«ããæåã³ã¼ãã§å®ç¾©ããã¦ãããæåã®å¤ã¨ããã©ã³ãã§æå®ããããã® CGGlyph ã®å¤ããããã³ã°ããªããã°ãªãã¾ããã
ãã®ããã®é¢æ°ã
void CGFontGetGlyphsForUnichars(CGFontRef, const UniChar[], const CGGlyph[], size_t);
ã§ã unicode ã®æ ¼ç´ãããæååã渡ãã¨ç°¡åã« CGGlyph ãæã«å ¥ãã¾ãããããããããã®é¢æ°ã¯ ããã¥ã¡ã³ããç¡ããiPhone ã¢ããªã§ä½¿ãã¨Appleãããªã¸ã§ã¯ãããããã¨ãå¤æãã¦ããé¢æ°ãªã®ã§åé¡ã«ãªãã¾ãã
ã¨ããã®ãã¾ã¨ãããã¦ããã®ããã¡ãã®ã¨ã³ããª
http://iphone-dev.g.hatena.ne.jp/ktakayama/20100129
ã§ãã©ããããã
ä¸ã®ã¨ã³ããªã¼ãè¦ãã¨ãããã®ã§ãããããã¤ãã®ç¬èªå®è£
ãããã®ã§ãã¡ãã使ãã¾ããé«é㧠thread safe ãªäºã«ãªã£ã¦ããã
http://www.mexircus.com/codes/GlyphDrawing.mm
ã®å®è£
ã¯ãã¾ãimport åºæ¥ãªãã£ãã®ã§ã2dã²ã¼ã ãã¬ã¼ã ã¯ã¼ã¯ã® cocos2d ã®ã³ã¼ãããå¿
è¦é¨åã ããæãåºãããã¡ã¤ã«ãä½ãã¾ããã
http://gist.github.com/raw/333978/d96a1a7a9f9824b8e3c8cf3ac6c45bf383b73763/GlyphTable.m
ãããã¦ã³ãã¼ãåºæ¥ã¾ãã
使ç¨ä¾ã¯ãããªæãã«ãªãã¾ãã
NSString* str = @"æç»ãããæåå"; CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"HiraKakuProN-W3"); fontTable* tbl = readFontTableFromCGFont(font); int originalLen = [str length]; CGGlyph _glyphs[[str length]]; unichar _chars[[str length]]; int i; for(i = 0; i < [str length]; i++) { _chars[i] = [str characterAtIndex:i]; } size_t griphLen = 0; mapCharactersToGlyphsInFont(tbl, _chars, originalLen, _glyphs, &griphLen);
ã©ã¤ã»ã³ã¹ã¯ãã¨ã®ãã¡ã¤ã«ã¨åãã Apache Licence 2.0 ã«ãªãã¾ãã®ã§å®å¿ãã¦ä½¿ãã¾ãã