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
730
おうちHackを取り入れた リノベーション事例
yusukeito
0
660
Server Side Swiftを しばらく運用してみた話
yusukeito
0
570
Swift からword2vecを 使ってみる
yusukeito
0
1k
Swift Outside the Box
yusukeito
1
2.5k
SwiftでgRPCとProtocolBuffersを使う
yusukeito
4
1.3k
Swift on Raspberry Pi でI2Cデバイスを使う
yusukeito
1
660
Isomorphic Swift
yusukeito
2
600
Swiftの値付きEnumをHackする
yusukeito
0
310
Other Decks in Programming
See All in Programming
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
11
1.8k
SwiftUI Viewの責務分離
elmetal
PRO
0
140
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
360
定理証明プラットフォーム lapisla.net
abap34
1
1.7k
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
110
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
660
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
730
Introduction to kotlinx.rpc
arawn
0
630
技術を根付かせる / How to make technology take root
kubode
1
240
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
130
Formの複雑さに立ち向かう
bmthd
1
720
GAEログのコスト削減
mot_techtalk
0
110
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
310
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
29
4.6k
A designer walks into a library…
pauljervisheath
205
24k
The Invisible Side of Design
smashingmag
299
50k
Rails Girls Zürich Keynote
gr2m
94
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Music & Morning Musume
bryan
46
6.3k
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
͝·͔͕͠ޮ͔ͳ͍ͷͰϑΥϯτͷ࣭͕͔Δ ώϥΪϊͷ͔ͬ͠Γ࡞ͬͯ͋Δҹ