macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

appendBezierPathWithGlyph:inFont:

INDEX>AppKit>NSBezier

指定したフォントの指定した字形のアウトラインパスを追加します

Objective-C

- (void)appendBezierPathWithGlyph:(NSGlyph)aGlyph
                           inFont:(NSFont *)fontObj

Swift

func appendBezierPathWithGlyph(_ aGlyph: NSGlyph,
                        inFont fontObj: NSFont)

解説

レシーバーにfontObjでaGlyphのアウトラインパスを追加します。

一文字書いてみる
f:id:jjj777:20150304204530p:plain

返り値

なし

引数

グリフ
Objective-C

(NSGlyph)aGlyph

Swift

aGlyph: NSGlyph

フォント
Objective-C

inFont:(NSFont *)fontObj

Swift

inFont fontObj: NSFont

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照


appendBezierPathWithGlyphs:count:inFont: - Cocoa API解説(iOS/OS X)


appendBezierPathWithPackedGlyphs: - Cocoa API解説(iOS/OS X)


drawPackedGlyphs:atPoint: - Cocoa API解説(iOS/OS X)

関連記事(外部サイト)


ios - NSGliff for Swift Dictionary Key - Using uintptr_t? - Stack Overflow


NSGlyph (Reserved Glyph Codes) - Cocoa in a Nutshell


objective c - How to draw one NSGlyph, that hasn't unicode representation? - Stack Overflow

例文

Objective-C

#import "MyView.h"

@implementation MyView

//NSViewのサブクラス MyViewのDrawRectに上書き
-(void)drawRect:(NSRect)rect
{
//NSFont *font =[NSFont fontWithName:@"Charcoal" size:36.0];
NSFont *font =[NSFont fontWithName:@"Osaka" size:36.0];
NSBezierPath *thePath = [NSBezierPath bezierPath];
//NSGlyph glyph= [font glyphWithName:@"a"];
NSGlyph glyph= 1234;
[thePath moveToPoint:NSMakePoint(200,200)];
[thePath lineToPoint:NSMakePoint(250,250)];
[thePath appendBezierPathWithGlyph:glyph
                            inFont:font
                                ];
[[NSColor blueColor] set];

[thePath stroke];
[thePath fill];

}

@end

Swift

    //NSBezierPath
    var aButton016 : NSButton?
    var aView016 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction016(sender : AnyObject?){
        //準備
        let aButton = aButton016
        let aView   = aView016
        var theWindow : NSWindow = aButton!.window!
        //準備ここまで
        
        //ビューにフォーカスを当てる
        aView?.lockFocus()
        //バックグラウンドカラーを描画
        let backgroundColor = NSColor.whiteColor()
        backgroundColor.setFill()
        NSRectFill(NSMakeRect(0, 20, 300.0, 178.0))
        
        NSColor.redColor().setStroke()
        NSColor.magentaColor().setFill()
        
        let myFont : NSFont = NSFont(name: "HiraMaruPro-W4", size: 69.0)!
        //空のベジェパスを作成
        let aBezier : NSBezierPath = NSBezierPath()
        //let aGlyph : NSGlyph = myFont.glyphWithName("gid5002")
        let aGlyph : NSGlyph = myFont.glyphWithName("gid1800")
        NSLog("glyph = %u",aGlyph)
        
        aBezier.moveToPoint(CGPoint(x: 125.0,y: 75.0))
        aBezier.appendBezierPathWithGlyph(aGlyph,  inFont: myFont)
        
        aBezier.fill()
        
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        NSLog("!!! %@",aBezier.description)
    }
    //実験用ウインドウ作成、実験用ビュー、実行ボタンを作成してウインドウに貼り付けるところまで
    @IBAction func function016(sender: AnyObject) {
        var aWindow : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            defer: false,
            screen: NSScreen.mainScreen())
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "NSBezierPath"//タイトル設定
        //ボタン
        var theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 0.0, 100.0, 30.0))
        theButton.title = "Action"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("viewAction016:")
        theButton.target = self
        
        aWindow.contentView.addSubview(theButton)
        //ビュー
        var theView : NSView = NSView(frame: NSMakeRect(0.0, 20.0, 300.0, 100.0))
        //レイヤーバックドにするのだ
        theView.wantsLayer = true
        aWindow.contentView.addSubview(theView)
        
        //実験ウインドウにUIパーツを渡す
        self.aButton016 = theButton    //ボタン
        self.aView016 = theView        //テストビュー
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

更新時バージョン

10.10