Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SwiftとCoreTextと文字組み

 SwiftとCoreTextと文字組み

Taishi Ikai

July 26, 2016
Tweet

More Decks by Taishi Ikai

Other Decks in Technology

Transcript

  1. 10

  2. 12  /4"UUSJCVUFE4USJOH͔Β$55ZQFTFUUFSΛੜ੒
 
  Ұߦͷ௕͞ %PVCMF Λ͋ͨ͑ͯɺվߦ͢Δ·Ͱͷจࣈ਺ ΛಘΔ var

    typesetter = CTTypesetterCreateWithAttributedString(
 attributedText) let count = CTTypesetterSuggestLineBreak(
 typesetter, 0, Double(lineWidth)) $PSF5FYUΛ࢖ͬͨඳըʕߦ಄ͷׅހΛͭΊΔฤ ໢ϝϩϯͷ୅ද඼छͰ͢ɻՌൽ͸྘৭Ͱશ໘ʹ
 ʹ 20 21 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
  3. 13  $55ZQFTFUUFS͔ΒҰߦ෼ͷ$5-JOFΛੜ੒
 
  ߦ಄͕࢝ΊׅހͳΒɺӈʹدͤΔ෼ͷ௕͞ΛಘΔ let ctline = CTTypesetterCreateLine(


    typesetter, CFRangeMake(0, count)) let offsetX = fontSize / 2 // ͱΓ͋͑ͣϑΥϯταΠζͷ൒෼ʹ $PSF5FYUΛ࢖ͬͨඳըʕߦ಄ͷׅހΛͭΊΔฤ ʢ
  4. 14  ӈʹدͤΔ෼Λઃఆͯ͠ɺ$5-JOFΛඳը
 
  ߦ਺෼͘Γ͔͑͢ CGContextSetTextPosition(context, offsetX, offsetY)
 CTLineDraw(ctline,

    context) $PSF5FYUΛ࢖ͬͨඳըʕߦ಄ͷׅހΛͭΊΔฤ ʢผ໊ʣϚεΫϝϩϯ ʢผ໊ʣϚεΫϝϩϯ