SlideShare ist ein Scribd-Unternehmen logo
1 von 20
CoreText
              By:

 SOURCEBITS   Ashish Asawa
              Aditya Sinha
 Demo
iOS Text Drawing
➢
  UIKit
➢
  Core Text
➢
  Core Graphics
UIKit
➢
  UILabel
➢
  UITextField
➢
  UITextView
Common Problems with UIKit
      Y can apply a font to the text, but the same font is used for the entire view.
       ou
    UITextView cannot display rich text from an NSAttributedString. There is no Apple-
                             provided view that can do that.


➢
    UIWebView
•
    Not ideal for displaying rich text.
•
    Requires HTML. 
•
    The native rich-text data structure  -> NSAttributedString
•
    Slow, and it provides no easy access to its current contents. 
Characters and Glyphs
Characters are essentially numbers representing code points in a character set
                             or encoding scheme.


OSX
✔
 Unicode
✔
 Provide unique number for every character
✔
 Independent of programming language, platform.
Glyphs continued..
                 A glyph is a graphic shape used to depict a character.


numeric codes
✔
                  glyph codes
✔
 Glyphs are selected during composition and layout processing by the character-to-glyph
conversion process.
There are any number of glyphs that correspond to a particular character.
✔
Understanding bold, Italics and Underline
✔
    Three most common rich-text attributes.
✔
    Presented to the user as simple attributes,
                       ✔
                           But they are quite different from each other.
✔
    In typography, you do not “bold” a font by drawing it with thicker lines. 
                                  ✔
                                      Font designer -> variation. 
✔
    In iOS the Helvetica font has a variation called Helvetica-Bold. 
✔
    While these fonts are related, they are completely different.
✔
    To find font variations, you use CTFontCreateCopyWithSymbolicTraits.
Italic
✔
  True italic type is based on calligraphy and uses different shapes (glyphs) than the regular (or
roman) font.
✔
     Some fonts do not have a true italic variation -> roman type -> oblique.
✔
    When users request italic, 
                                             Either italic or oblique. 
                                             ✔



✔
    kCTFontItalicTrait to CTFontCreateCopyWithSymbolicTraits
                       ✔
                           It returns the best font that matches this looser definition.
✔
     Text with both bold and italic requires yet another font variation such as Georgia-BoldItalic.
✔
    Underline is a decoration like color or shadow. 
                            ✔
                                You do not change font when you add decorations.
Core Text
Core Text is a C-based API that uses Core Foundation naming and memory
                               management.
Low-level text layout and font-handling engine.
➢



Extremely fast and powerful. 
➢



Can handle complex layouts
➢



Multicolumn text 
➢



Curved text.
➢
Attributed Strings

 The fundamental data type in Core Text is CFAttributedString. An attributed string is a
string that applies attributes to ranges of characters. 



 The attributes can be any key-value pair, but for the purposes of Core Text, they
usually contain style information such as font, color, and indentation.



 It is usually best to use CFMutableAttributedString so you can modify the attributes
of various parts of the string. CFAttributedString requires that all of the string have the
same attributes.



    Toll free bridge to Cocoa Attributed String (NSAttributed String)
CoreText Objects
➢CTFramesetter
➢Typesetters
➢Lines   and Glyph Runs
CTFrameSetter
●
  Highest level object in core text layout engine
●
  Generates text frame by filling path with text
●
  Applies paragraph styles to the frame text
Typesetters
➢  Performs the fundamental text layout operations of character-to-
glyph conversion
➢ Positioning of glyphs into lines.

➢ Suggests line breaks.

➢ CTFramesetter instantiates a typesetter and uses it to create the
line objects used to fill a frame
Lines and Glyph Runs
➢CTLine : CoreText Object that represents a line
➢Contains an array of glyph runs

➢Glyph run is a set of consecutive glyphs sharing the same attributes

and direction
➢Created by typesetter during framesetting operations
CoreText: Things NOT Covered
➢
    CTFont
➢
    Run Delegate
             - to attach pic, movie in the middle of document
             ➢


➢
    Presenting Big Document
➢
    Writing CT to pdf
➢
    NSAttributed String and Core Text - ios6
➢
    Mixing Different Languages.
➢
    CT Editor ?
Conclusion
•In the vast majority of cases, UIKit views like UILabel, UITextView, UITextFields are perfectly
adequate. 
•   If you need a just few stylized words, you can break the sentence into multiple UILabel views.
•   For complex styles, UIKit views are insufficient.
•The next tool you should consider is custom view drawing with NSString methods such as
drawInRect:withFont:. This approach is very good for static text.
•If you need to draw highly stylized, dynamic text, then you basically have two options: web views
and Core Text. 
•   For selectable and editable text, the best option is typically a web view.
                                     •   Javascript knowledge is required.
•
Conclusion continued..
●
    If you don’t need to edit your rich text, then Core Text is a good choice. 
●
 If you need to perform very complex layout, such as drawing along curves, Core Text may be your only
option.
●
    Core Text does not include any capability for text selection, or copy and paste. 
●
    If you use Core Text, to get good performance use as much as foundation classes.
●
    If the user needs to select text, you need to implement that by hand.
●
  Whichever option you choose, try to keep your text rendering isolated to a small number of classes so
that you can swap out the engine later.
●
    Apple often tries out complicated APIs in its own code before making them public.
●
    Eg : UIPageViewController, UICollectionView
References
●Core Text Programming Guide
●Quartz 2D Programming Guide.  "Text"
●String Programming Guide. “Drawing Strings”
●Text, Web, and Editing Programming Guide

●WWDC   2011 videos.
     "Session 511 – Rich Text Editing in Safari on iOS"
●WWDC   2010 videos.
        "Session 110 - Advanced Text Handling for iPhone OS"
●http://www.planetclegg.com/projects/WarpingTextToSplines.html
?
Thank You
Presenters:



Ashish Asawa   – ashish.asawa@sourcebits.com
Aditya Sinha   – aditya.sinha@sourcebits.com

Weitere ähnliche Inhalte

Ähnlich wie Core text

Ähnlich wie Core text (20)

SPC Unit 2
SPC Unit 2SPC Unit 2
SPC Unit 2
 
Swift programming language
Swift programming languageSwift programming language
Swift programming language
 
Indian Language App.Development Framework for Android
Indian Language App.Development Framework for AndroidIndian Language App.Development Framework for Android
Indian Language App.Development Framework for Android
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
 
UCSY CS Club Week2
UCSY CS Club Week2UCSY CS Club Week2
UCSY CS Club Week2
 
Programming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharProgramming languages and concepts by vivek parihar
Programming languages and concepts by vivek parihar
 
Benefits of Typescript.pptx
Benefits of Typescript.pptxBenefits of Typescript.pptx
Benefits of Typescript.pptx
 
Text
TextText
Text
 
Julie Strawson
Julie StrawsonJulie Strawson
Julie Strawson
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Bonding with Pango
Bonding with PangoBonding with Pango
Bonding with Pango
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventionsHTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages
 
Bringing a Design Language to Life in Sketch and React
Bringing a Design Language to Life in Sketch and ReactBringing a Design Language to Life in Sketch and React
Bringing a Design Language to Life in Sketch and React
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptx
 
The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)
 
English de lenguaje de programacion
English de lenguaje de programacionEnglish de lenguaje de programacion
English de lenguaje de programacion
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Core text

  • 1. CoreText By: SOURCEBITS Ashish Asawa Aditya Sinha Demo
  • 2. iOS Text Drawing ➢ UIKit ➢ Core Text ➢ Core Graphics
  • 3. UIKit ➢ UILabel ➢ UITextField ➢ UITextView
  • 4. Common Problems with UIKit Y can apply a font to the text, but the same font is used for the entire view. ou UITextView cannot display rich text from an NSAttributedString. There is no Apple- provided view that can do that. ➢ UIWebView • Not ideal for displaying rich text. • Requires HTML.  • The native rich-text data structure  -> NSAttributedString • Slow, and it provides no easy access to its current contents. 
  • 5. Characters and Glyphs Characters are essentially numbers representing code points in a character set or encoding scheme. OSX ✔ Unicode ✔ Provide unique number for every character ✔ Independent of programming language, platform.
  • 6. Glyphs continued.. A glyph is a graphic shape used to depict a character. numeric codes ✔ glyph codes ✔ Glyphs are selected during composition and layout processing by the character-to-glyph conversion process. There are any number of glyphs that correspond to a particular character. ✔
  • 7. Understanding bold, Italics and Underline ✔ Three most common rich-text attributes. ✔ Presented to the user as simple attributes, ✔ But they are quite different from each other. ✔ In typography, you do not “bold” a font by drawing it with thicker lines.  ✔ Font designer -> variation.  ✔ In iOS the Helvetica font has a variation called Helvetica-Bold.  ✔ While these fonts are related, they are completely different. ✔ To find font variations, you use CTFontCreateCopyWithSymbolicTraits.
  • 8. Italic ✔ True italic type is based on calligraphy and uses different shapes (glyphs) than the regular (or roman) font. ✔  Some fonts do not have a true italic variation -> roman type -> oblique. ✔ When users request italic,  Either italic or oblique.  ✔ ✔ kCTFontItalicTrait to CTFontCreateCopyWithSymbolicTraits ✔ It returns the best font that matches this looser definition. ✔  Text with both bold and italic requires yet another font variation such as Georgia-BoldItalic. ✔ Underline is a decoration like color or shadow.  ✔ You do not change font when you add decorations.
  • 9. Core Text Core Text is a C-based API that uses Core Foundation naming and memory management. Low-level text layout and font-handling engine. ➢ Extremely fast and powerful.  ➢ Can handle complex layouts ➢ Multicolumn text  ➢ Curved text. ➢
  • 10. Attributed Strings  The fundamental data type in Core Text is CFAttributedString. An attributed string is a string that applies attributes to ranges of characters.   The attributes can be any key-value pair, but for the purposes of Core Text, they usually contain style information such as font, color, and indentation.  It is usually best to use CFMutableAttributedString so you can modify the attributes of various parts of the string. CFAttributedString requires that all of the string have the same attributes.  Toll free bridge to Cocoa Attributed String (NSAttributed String)
  • 12. CTFrameSetter ● Highest level object in core text layout engine ● Generates text frame by filling path with text ● Applies paragraph styles to the frame text
  • 13. Typesetters ➢ Performs the fundamental text layout operations of character-to- glyph conversion ➢ Positioning of glyphs into lines. ➢ Suggests line breaks. ➢ CTFramesetter instantiates a typesetter and uses it to create the line objects used to fill a frame
  • 14. Lines and Glyph Runs ➢CTLine : CoreText Object that represents a line ➢Contains an array of glyph runs ➢Glyph run is a set of consecutive glyphs sharing the same attributes and direction ➢Created by typesetter during framesetting operations
  • 15. CoreText: Things NOT Covered ➢ CTFont ➢ Run Delegate - to attach pic, movie in the middle of document ➢ ➢ Presenting Big Document ➢ Writing CT to pdf ➢ NSAttributed String and Core Text - ios6 ➢ Mixing Different Languages. ➢ CT Editor ?
  • 16. Conclusion •In the vast majority of cases, UIKit views like UILabel, UITextView, UITextFields are perfectly adequate.  • If you need a just few stylized words, you can break the sentence into multiple UILabel views. • For complex styles, UIKit views are insufficient. •The next tool you should consider is custom view drawing with NSString methods such as drawInRect:withFont:. This approach is very good for static text. •If you need to draw highly stylized, dynamic text, then you basically have two options: web views and Core Text.  • For selectable and editable text, the best option is typically a web view. • Javascript knowledge is required. •
  • 17. Conclusion continued.. ● If you don’t need to edit your rich text, then Core Text is a good choice.  ● If you need to perform very complex layout, such as drawing along curves, Core Text may be your only option. ● Core Text does not include any capability for text selection, or copy and paste.  ● If you use Core Text, to get good performance use as much as foundation classes. ● If the user needs to select text, you need to implement that by hand. ● Whichever option you choose, try to keep your text rendering isolated to a small number of classes so that you can swap out the engine later. ● Apple often tries out complicated APIs in its own code before making them public. ● Eg : UIPageViewController, UICollectionView
  • 18. References ●Core Text Programming Guide ●Quartz 2D Programming Guide.  "Text" ●String Programming Guide. “Drawing Strings” ●Text, Web, and Editing Programming Guide ●WWDC 2011 videos.   "Session 511 – Rich Text Editing in Safari on iOS" ●WWDC 2010 videos. "Session 110 - Advanced Text Handling for iPhone OS" ●http://www.planetclegg.com/projects/WarpingTextToSplines.html
  • 19. ?
  • 20. Thank You Presenters: Ashish Asawa – ashish.asawa@sourcebits.com Aditya Sinha – aditya.sinha@sourcebits.com