Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CoreText のはなし
Search
Yusuke Ito
April 14, 2012
Programming
6
4.3k
CoreText のはなし
http://atnd.org/events/26946
Yusuke Ito
April 14, 2012
Tweet
Share
More Decks by Yusuke Ito
See All by Yusuke Ito
Macとオーディオ再生 2024/11/02
yusukeito
0
370
おうちHackを取り入れた リノベーション事例
yusukeito
0
630
Server Side Swiftを しばらく運用してみた話
yusukeito
0
560
Swift からword2vecを 使ってみる
yusukeito
0
1k
Swift Outside the Box
yusukeito
1
2.4k
SwiftでgRPCとProtocolBuffersを使う
yusukeito
4
1.3k
Swift on Raspberry Pi でI2Cデバイスを使う
yusukeito
1
640
Isomorphic Swift
yusukeito
2
580
Swiftの値付きEnumをHackする
yusukeito
0
290
Other Decks in Programming
See All in Programming
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
役立つログに取り組もう
irof
28
9.6k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
880
Better Code Design in PHP
afilina
PRO
0
130
最新TCAキャッチアップ
0si43
0
140
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Realtime API 入門
riofujimon
0
150
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.6k
Statistics for Hackers
jakevdp
796
220k
Music & Morning Musume
bryan
46
6.2k
How GitHub (no longer) Works
holman
310
140k
Fireside Chat
paigeccino
34
3k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
RailsConf 2023
tenderlove
29
900
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Six Lessons from altMBA
skipperchong
27
3.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Transcript
͋ ͭ CoreText ͷͳ͠ Yusuke Ito, @novi_
֓ཁ ग़ݱ: 3.2 (iPad only) 2010/4/3 (3.0͔Β͕͋ͬͨ·ͩPrivate) ςΩετϨϯμϦϯάΤϯδϯ TextEdit, Cocoa(NSText*)ͰΘΕ͍ͯΔ
may be Pages, iMovie, Keynote ....
iOS ͱ OS X AttributedStringͱηοτͰ͏ (ඳըCoreGraphics) RTLɾॎॻ͖༻άϦϑʹରԠ→ॎॻ͖ άϦϑͷஔ (CTGlyphInfo) ҟମࣈʹ͑Δ
ϑΥϯτͷબ(σΟεΫϦϓλ) (CTFontDescriptor) ϑΥϯτϑΝΠϧͷύʔεɾ֤छϝλσʔλ (CTFont)
CoreText.framework (iOS) ApplicationServices.framework/CoreText.framework (OS X) CݴޠͷΠϯλʔϑΣʔε CoreFoundationϕʔε CFTypeΛܧঝ(ͱͯ͠ৼΔ͏)
NSAttributedString CFAttributedStringͱToll-free NSMutableAttributedString, CFMutableAttributedString म০จࣈ (৭ɾϑΥϯτɾߦؒ...) Λදݱ͢ΔΫϥε ෦จࣈྻʹରͯ͠ɺ৭(ଐੑ)ͳͲΛઃఆ͢Δ iOS4.0૬Ҏ্͔ΒBlocksʹΑΔଐੑͷྻڍΛα ϙʔτ
Ͳ͏Ͱྑ͍ ☞ ࣌ iOS3.2 ☞ CoreText͕͑ΔΑ͏ʹͳͬͨ ☞ ॎॻ͖͕Ͱ͖Δ!! (ΞςʹͳΒͳ͍υΩϡϝϯτʹΑ Δͱʣ
☞ ͔͠͠ɺग़དྷͳ͍!! ☞ Macͱಉ͡ίʔυͰग़དྷͳ͍!!
☞ υΩϡϝϯτʹࡌ͍ͬͯΔͷʹ... (͑Δͱॻ͍ ͯ͋Δ) ☞ ͍ͭ௨Γग़དྷͳ͍ΜͩΖ͏→ఘΊΔ ☞ ͱΓ͋͑ͣAppleʹόάϨϙ ☞ ςετίʔυΛૹΕͱݴΘΕΔ
☞ iOSͱMac༻ʹ࡞ͬͯૹΔ ☞ εΫϦʔϯγϣοτΛૹΔ ☞ ͦͯ͠ɺԻࠫଡແ͠...
ޙ J04ϦϦʔεલ
Apple: “ग़དྷͨΑʔ” ͓ͤʔΑ!!! ͱ͍͏͜ͱͰɺ ࠓॎॻ͖Ͱ͖·͢ɻ
αϙʔτ͞Ε͕ͨ... όΪʔͩͬͨ! ߦͷRTL(Right to Left)ɺॎॻ͖ܥ͕·ͱʹग़དྷͳ͍ RTLϞʔυͩͱάϦϑͷbounds͕͓͔͍͠ Unicodeॲཧएׯ͓͔͍͠ (ؾ͕͢Δ) ຊޠͱԤจϑΥϯτࠞ߹࣌ͷߦؒ (༷)
͍͔ͭ͘ͷτϦοΫͰमਖ਼Մೳ
αϙʔτ͞Ε͕ͨ... ϑΥϯτσΟεΫϦϓλʹຊޠΛ৯ΘͤΔͱམͪΔ ώϥΪϊҎ֎·ͱʹϨϯμϦϯά͞Εͳ͍͜ͱ (e.g.) IPA TrueType ϑΥϯτͷॎॻ͖͕·ͱʹͰ ͖ͳ͍ ԣOKɺॎ͕μϝ (ϑΥϯτͷ༷͔)
FontForgeͰίϯόʔτͯͩ͠Ί
How to Use ࠶ͼ: AttributedStringͱηοτͰ͏ ࣮ࡍͷඳըCoreGraphics (ྫ͑-drawRect:) ViewUIViewΛܧঝͯࣗ͠Ͱ࣮ ៉ྷͳ݁ՌΛಘΔʹ៉ྷͳAttributedStringΛ࡞ΕΔ ͔ɻͨͿΜϙΠϯτͬͪ͜ɻ
ͱ͍͏͜ͱͰɺAttributedStringͷͳ͠
1. Attributed StringΛ࡞Δ ଐੑ Core Text String Attributes Λ͏ NSAttributedStringʹCFAttributedString
NSMutableAttributedStringʹCFMutableAttributedString ී௨Cocoa(NS)Λ͑OK
2. CoreTextͰϨϯμϦϯά 1Ͱ࡞ͨ͠NSAttributedString͔ΒCoreTextͷΦϒ δΣΫτΛ࡞ CTFramesetterCreateWithAttributedString ͳͲ ϨϯμϦϯά CTFramesetterCreateFrame → CTFrameʹม
3. CoreGraphicsͰඳը͢Δ 1.CTFrameͷDraw(CTFrameDraw)Λ͏ 2.CTLineͷDrawΛ͏→ࣗͰߦ͝ͱඳը 1.ۉἧ͑Λ͢Δͱ͖͜ΕΛ͏ 3.CTRunͷDrawΛ͏ 4.CTRun͔ΒάϦϑCGGlyphΛऔΓग़ͯ͠ɺ CGContextShowGlyphsͰඳը͢Δɻ ͍ͣΕ͔ͷํ๏Ͱඳը
CTFrameSetter NSAttributedString CTFrame CTFont CTGlyphInfo CTParagraph Style CTLine CTLine CTLine
CTRun CoreGraphics -drawRect: CTLine ϨϯμϦϯά ඳը ଐੑͱͯ͠ઃఆ ॳظԽ
ࣈ123 Hello World ࣈ123 ... NSAttributedString Hello World CTLine
ࣈ 123 CTLine CTRun
CTFrameSetter NSAttributedString CTFrame CTLine CTLine CTLine ϨϯμϦϯά ॳظԽ ࠓ·ͰͷΑ͘հ͞Ε͍ͯΔ Γํ
࣮ࡍCTFramesetterɺ CTTypesetterΛ෦Ͱಈ͔͍ͯ͠Δ CTTypesetter NSAttributedString CTLine CTLine CTLine ࣗͰߦΛ࡞ͬͯ ϨϯμϦϯά ॳظԽ
͏ҰͭͷΓํ: CTTypesetterΛ͏ ී௨࠷ॳʹհͨ͠΄͏Ͱे
͜͜ͰσβΠϯύλʔϯͷͰ ΦϒδΣΫτMutable(Մม)͔Immutable(ෆม)͔ Mutable: NSMutable..., UIView, UIViewController... Immutable: NSObject, NSString, UIImage,
UIColor... NSMutableAttributedString จࣈྻࣗମImmutable (-initWithString:) จࣈྻͷଐੑMutable (-setAttributes:range:) CoreTextͯ͢Immutable
CTFrameSetter NSAttributedString NSMutableAttributed... CTFrame CTFont CTGlyphInfo CTParagraph Style CTLine CTLine
CTLine CTRun CTLine ϨϯμϦϯά ଐੑͱͯ͠ઃఆ ΠχγϟϥΠβʔ CTFramesetterCreateWithAttributedString CTFramesetterCr eateFrame औΓग़͠ CTFrameGetLines औΓग़͠ CTLineGetGlyphRuns Imuutable Imuutable Imuutable Imuutable Imuutable Imuutable ಈతͳมߋ͍͠ͷͰ͏·͘ઃܭ͠·͠ΐ͏ɻ
Ͱ͖Δ or Ͱ͖ͳ͍, FAQ ϦϯΫΤϥʔ iOSCoreText.frameworkͷՃ(ϦϯΫ)͕ඞཁ ඳը࣌ͷαΠζ͕ཉ͍͠ CTFramesetterSuggestFrameSizeWithConstraints ۉஔ CTLineCreateJustifiedLineͰCTLineΛมͯ͠
CTLine͝ͱඳը
ը૾ಈըΛຒΊࠐΜͰϨϯμϦϯά AttributedStringʹจࣈU+FFFCΛهͯ͠ɺ kCTRunDelegateAttributeName ଐੑͰCTRunDelegateΛઃఆ ͢Δͱࢦఆͨ͠αΠζͷۭ͖ྖҬ͕Ͱ͖Δ→͜͜ʹޙͰࣗͰ ViewΛஔ͘ ඳը࣌ʹCTRunGetAttributesͰCTRunDelegateΛऔಘ ͨͩ͠ɺViewࣗͰஔ͍ͯͶ
άϦϑͷஔ kCTGlyphInfoAttributeNameଐੑͰ CTGlyphInfo Λ ηοτ લiOSͰಈ͔ͳ͔͕࣮ͬͨ͞Εͨ ߦؒͳͲͷஈམͷઃఆ kCTParagraphStyleAttributeNameଐੑͰ CTParagraphStyle Ληοτ
ຊޠͱԤจࠞࡏ࣌ʹߦ͕ؒෆࣗવ ํ๏1: ߦؒΛࣗͰۭ͚ͳ͕ΒɺCTLine͝ͱʹඳը ํ๏2: kCTParagraphStyleSpecifierMinimumLineSpacing, kCTParagraphStyleSpecifierMaximumLineSpacing Λ0.0 ʹηοτ (͜ͷଐੑυΩϡϝϯτʹࡌ͍ͬͯͳ͍ͷ ͰҙɻϔομϑΝΠϧࢀর)
ॎॻ͖ (࣍ͷ2ͭͷ࡞ۀ͕ඞཁ) ॎॻ͖ͷάϦϑʹ͢Δ: kCTVerticalFormsAttributeName ߦΛॎஔ͖Ͱɺӈ͔Βࠨʹඳը͢Δ: ํ๏1: kCTFrameProgressionAttributeName (LineͳͲͷboundsऔಘͰόά͕͋Δؾ͕͢Δ) ํ๏2: CGContextͰMatrix(CGAffineTransform)Λ
ηοτͯ͠ճసͤ͞Δ
ςΩετΤσΟλతͳͷΛ࡞Δ UITextInput Protocol ͔Β࢝ΊΔ Text, Web, and Editing Programming Guide
for iOS
͓͢͢ΊReference ެࣜ: ATSUIΛͬͨUnicodeςΩετඳը ͏άάͬͯग़ͯ͜ͳ͍͕ɺWebArchiveʹ͋ͬͨɻ http://bit.ly/Hh7sP3 ެࣜ: Core Text Reference Attributed
String Programming Guide Core Text String Attributes Reference NSMutableAttributedString Class Reference Strings Programming Guide for Core Foundation
Reference 2 WWDC Video #110, 2010, Advanced Text Handling for
iPhone OS #114, 2010, Advanced Cocoa Text Tips and Tricks #128, 2011, Advanced Text Processing Google ݕࡧ: “coretext filetype:pdf” “attributed string filetype:pdf” SlideShare, SpeakerDeck Github
LTCoreText ͦΕͳΓʹܰྔ ϖʔδϯά/ ஈΈ ॎஔ͖/ॎॻ͖ ΧελϜϏϡʔͷຒΊࠐΈ ಈతͳϖʔδૠೖɾআ ඇಉظϨΠΞτॲཧ https://github.com/novi/LTCoreText ͓·͚:
LTGridView ్த͚ͩͲGridViewͷϥΠϒϥϦ ެ։தͷϥΠϒϥϦ
demo LTCoreText
Thank you ❡ https://github.com/novi http://speakerdeck.com/u/yusukeito http://about.me/yusukeito
Appendix: RetinaͱCoreText Retinaͩͱएׯจࣈ͕ࡉ͘ݟ͑Δ (ͱࢥ͏) αϒϐΫηϧϨϯμϦϯάͷON/OFFʹΑͬͯҧ͏ Retina/ඇRetina, αϒϐΫηϧϨϯμϦϯάON/OFF ͷ4ύλʔϯ MacσϑΥϧτON, iOSOFF
͝·͔͕͠ޮ͔ͳ͍ͷͰϑΥϯτͷ࣭͕͔Δ ώϥΪϊͷ͔ͬ͠Γ࡞ͬͯ͋Δҹ