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
600
おうちHackを取り入れた リノベーション事例
yusukeito
0
650
Server Side Swiftを しばらく運用してみた話
yusukeito
0
570
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
650
Isomorphic Swift
yusukeito
2
590
Swiftの値付きEnumをHackする
yusukeito
0
300
Other Decks in Programming
See All in Programming
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
6
1.3k
GitHubで育つ コラボレーション文化 : ニフティでのインナーソース挑戦事例 - 2024-12-16 GitHub Universe 2024 Recap in ZOZO
niftycorp
PRO
0
1.1k
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
360
情報漏洩させないための設計
kubotak
5
1.2k
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
330
Beyond ORM
77web
11
1.5k
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
340
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
240
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
230
CloudflareStack でRAGに入門
asahiiwm
0
140
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
980
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.3k
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
521
39k
How STYLIGHT went responsive
nonsquared
96
5.3k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Documentation Writing (for coders)
carmenintech
67
4.5k
Building an army of robots
kneath
302
44k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Thoughts on Productivity
jonyablonski
68
4.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
͝·͔͕͠ޮ͔ͳ͍ͷͰϑΥϯτͷ࣭͕͔Δ ώϥΪϊͷ͔ͬ͠Γ࡞ͬͯ͋Δҹ