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. !.FMPOTXJGU
    ழࣂେࢤ೔ຊܦࡁ৽ฉࣾ
    4XJGUͱ$PSF5FYUͱจࣈ૊Έ

    View full-size slide

  2. 2
    ழࣂେࢤʢ*LBJ5BJTIJʣ
    ೔ຊܦࡁ৽ฉࣾͷΤϯδχΞ
    ࢴ໘ϏϡʔΞʔΞϓϦͷ։ൃ
    4XJGU/PEFKT1ZUIPO
    ϝϩϯ೿
    ࣗݾ঺հ

    View full-size slide

  3. จࣈ૊Έ͍ͯ͠·͔͢ʁ
    3

    View full-size slide

  4. 4
    ग़యIUUQPFDOFUTZPLV[BJNFMPO
    ΞʔϧεɾϑΣϘϦοτ
    ʢผ໊ʣϚεΫϝϩϯ
    ໢ϝϩϯͷ୅ද඼छͰ͢ɻՌൽ͸྘৭Ͱશ໘
    ʹඒ͍͠໢໨໛༷͕Ͱ͍ͯ·͢ɻ

    View full-size slide

  5. 5
    ग़యIUUQPFDOFUTZPLV[BJNFMPO
    ΞʔϧεɾϑΣϘϦοτ
    ʢผ໊ʣϚεΫϝϩϯ
    ໢ϝϩϯͷ୅ද඼छͰ͢ɻՌൽ͸྘৭Ͱશ໘
    ʹඒ͍͠໢໨໛༷͕Ͱ͍ͯ·͢ɻ

    View full-size slide

  6. 6
    ग़యIUUQPFDOFUTZPLV[BJNFMPO
    ΞʔϧεɾϑΣϘϦοτ
    ʢผ໊ʣϚεΫϝϩϯ
    ໢ϝϩϯͷ୅ද඼छͰ͢ɻՌൽ͸྘৭Ͱશ໘
    ʹඒ͍͠໢໨໛༷͕Ͱ͍ͯ·͢ɻ

    View full-size slide

  7. 7
    ग़యIUUQPFDOFUTZPLV[BJNFMPO
    ΞʔϧεɾϑΣϘϦοτ
    ʢผ໊ʣϚεΫϝϩϯ
    ໢ϝϩϯͷ୅ද඼छͰ͢ɻՌൽ͸྘৭Ͱશ໘
    ʹඒ͍͠໢໨໛༷͕Ͱ͍ͯ·͢ɻ
    ʢผ໊ʣ

    View full-size slide

  8. ΞʔϧεɾϑΣϘϦοτ
    ໢ϝϩϯͷ୅ද඼छͰ͢ɻՌൽ͸྘৭Ͱશ໘
    ʹඒ͍͠໢໨໛༷͕Ͱ͍ͯ·͢ɻ
    ʢผ໊ʣϚεΫϝϩϯ
    8
    ग़యIUUQPFDOFUTZPLV[BJNFMPO
    ʢผ໊ʣ
    ʢผ໊ʣ

    View full-size slide

  9. 9
    ग़యIUUQPFDOFUTZPLV[BJNFMPO
    ΞʔϧεɾϑΣϘϦοτ
    ໢ϝϩϯͷ୅ද඼छͰ͢ɻՌൽ͸྘৭Ͱશ໘
    ʹඒ͍͠໢໨໛༷͕Ͱ͍ͯ·͢ɻ
    ʢผ໊ʣϚεΫϝϩϯ

    View full-size slide

  10. ߦ಄ͷׅހΛͭΊΔฤ
    $PSF5FYUΛ࢖ͬͨඳը
    11

    View full-size slide

  11. 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

    View full-size slide

  12. 13
    $55ZQFTFUUFS͔ΒҰߦ෼ͷ$5-JOFΛੜ੒


    ߦ಄͕࢝ΊׅހͳΒɺӈʹدͤΔ෼ͷ௕͞ΛಘΔ
    let ctline = CTTypesetterCreateLine(

    typesetter, CFRangeMake(0, count))
    let offsetX = fontSize / 2 // ͱΓ͋͑ͣϑΥϯταΠζͷ൒෼ʹ
    $PSF5FYUΛ࢖ͬͨඳըʕߦ಄ͷׅހΛͭΊΔฤ
    ʢ

    View full-size slide

  13. 14
    ӈʹدͤΔ෼Λઃఆͯ͠ɺ$5-JOFΛඳը


    ߦ਺෼͘Γ͔͑͢
    CGContextSetTextPosition(context, offsetX, offsetY)

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

    View full-size slide

  14. 15
    /4"UUSJCVUFE4USJOHΑΓ΋̏ഒ͘Β͍஗͍
    จࣈ͕ଟ͘ͳΔͱɺNT NT
    Λ௒͑Δ
    ͜ͱ΋
    ಛʹ$55ZQFTFUUFS$SFBUF8JUI"UUSJCVUFE4USJOH͕ॏ͍
    ͸͍ͭ͜ͷ࣌ؒ
    "UUSJCVUFΛଟ͋ͯ͘Δͱ஗͘ͳΔ
    ύϑΥʔϚϯε

    View full-size slide

  15. HJUIVCDPNJLBJU,FSO-BCFM
    16
    ߦ಄Ґஔௐ੔ɺࠨɾதԝɾӈɾۉ౳ἧ͑ɺ

    ྡ઀͢Δ໿෺ͷִؒΛௐ੔ɺ۟ಡ఺ͷ௥͍ग़͠ͳͲ
    ϥΠϒϥϦΛ͍ͭͬͯ͘·͢

    View full-size slide

  16. $PSF5FYU͸4XJGUͰͲ͏มԽ
    17
    ͓·͚

    View full-size slide

  17. 18
    4XJGU 4XJGU
    $PSF(SBQIJDT

    View full-size slide

  18. 19
    4XJGU 4XJGU
    $PSF(SBQIJDT

    View full-size slide

  19. 20
    $PSF5FYU
    4XJGU 4XJGU

    View full-size slide