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
200
おうちHackを取り入れた リノベーション事例
yusukeito
0
620
Server Side Swiftを しばらく運用してみた話
yusukeito
0
550
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
色々なIaCツールを実際に触って比較してみる
iriikeita
0
270
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
400
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
920
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
160
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
170
Vue.js学習の振り返り
hiro_xre
2
130
EventSourcingの理想と現実
wenas
6
2.1k
CSC509 Lecture 09
javiergs
PRO
0
110
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
52
32k
Featured
See All Featured
Practical Orchestrator
shlominoach
186
10k
Documentation Writing (for coders)
carmenintech
65
4.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
The Cult of Friendly URLs
andyhume
78
6k
A Philosophy of Restraint
colly
203
16k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
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
͝·͔͕͠ޮ͔ͳ͍ͷͰϑΥϯτͷ࣭͕͔Δ ώϥΪϊͷ͔ͬ͠Γ࡞ͬͯ͋Δҹ