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
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2.6k
ペアーズでの、Langfuseを中心とした評価ドリブンなリリースサイクルのご紹介
fukubaka0825
2
300
Grafana Cloudとソラカメ
devoc
0
140
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
660
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
270
『品質』という言葉が嫌いな理由
korimu
0
160
CNCF Project の作者が考えている OSS の運営
utam0k
5
690
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
360
Djangoアプリケーション 運用のリアル 〜問題発生から可視化、最適化への道〜 #pyconshizu
kashewnuts
1
230
Spring gRPC について / About Spring gRPC
mackey0225
0
220
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
160
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
50
11k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
Code Review Best Practice
trishagee
66
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Raft: Consensus for Rubyists
vanstee
137
6.8k
Become a Pro
speakerdeck
PRO
26
5.1k
Adopting Sorbet at Scale
ufuk
74
9.2k
RailsConf 2023
tenderlove
29
1k
Building an army of robots
kneath
302
45k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
12
950
Optimising Largest Contentful Paint
csswizardry
34
3.1k
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
͝·͔͕͠ޮ͔ͳ͍ͷͰϑΥϯτͷ࣭͕͔Δ ώϥΪϊͷ͔ͬ͠Γ࡞ͬͯ͋Δҹ