All Projects → frankrausch → Typographizer

frankrausch / Typographizer

Licence: mit
Fix dumb quotation marks and apostrophes in Swift on iOS, macOS, watchOS, and tvOS

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Typographizer

Typesetter
Android tool to help display changes to text positioning.
Stars: ✭ 149 (-37.39%)
Mutual labels:  typography
Scrollinglettersanimation
A switching title effect where a fixed element changes depending on the scroll position.
Stars: ✭ 197 (-17.23%)
Mutual labels:  typography
Leerraum.js
A PDF typesetting library with exact positioning and hyphenated line breaking
Stars: ✭ 233 (-2.1%)
Mutual labels:  typography
Mesh
A toolkit for Kinetic Web Typography
Stars: ✭ 167 (-29.83%)
Mutual labels:  typography
Fnt
apt for fonts, the missing font manager for macOS/linux
Stars: ✭ 187 (-21.43%)
Mutual labels:  typography
Sky Design
🌃 the design reference for the developers who care about good design.
Stars: ✭ 199 (-16.39%)
Mutual labels:  typography
Typeit
The most versatile JavaScript typewriter effect library on the planet.
Stars: ✭ 2,406 (+910.92%)
Mutual labels:  typography
Mnml Ghost Theme
A minimal, responsive, fast ghost blog theme with great typography. Comes with paid membership support, Disqus comments, syntax highlighting, and KaTeX for mathematics, and more.
Stars: ✭ 235 (-1.26%)
Mutual labels:  typography
Typeset.css
A no-nonsense CSS typography reset for styling user-generated content like blog posts, comments, and forum content.
Stars: ✭ 192 (-19.33%)
Mutual labels:  typography
Sassy Gridlover
Super easy to use Sass mixins to establish a typographic system with modular scale and vertical rhythm. Based on the Gridlover app.
Stars: ✭ 223 (-6.3%)
Mutual labels:  typography
Han
「漢字標準格式」印刷品般的漢字排版框架 Han.css: the CSS typography framework optimised for Hanzi.
Stars: ✭ 2,156 (+805.88%)
Mutual labels:  typography
Graaf
A collection of pure CSS grids for designing your new projects
Stars: ✭ 186 (-21.85%)
Mutual labels:  typography
Scsscale
Typographic modular scale starter based on body's font-size built on SCSS.
Stars: ✭ 206 (-13.45%)
Mutual labels:  typography
Harfbuzz
HarfBuzz text shaping engine
Stars: ✭ 2,206 (+826.89%)
Mutual labels:  typography
Typefaces
NPM packages for Open Source typefaces
Stars: ✭ 2,581 (+984.45%)
Mutual labels:  typography
Handwrite
Handwrite generates a custom font based on your handwriting sample.
Stars: ✭ 145 (-39.08%)
Mutual labels:  typography
Tipograf
Lightweight pure CSS typography base for your next project
Stars: ✭ 198 (-16.81%)
Mutual labels:  typography
Swiftrichstring
👩‍🎨 Elegant Attributed String composition in Swift sauce
Stars: ✭ 2,744 (+1052.94%)
Mutual labels:  typography
Figma Export
Command line utility to export colors, typography, icons and images from Figma to Xcode / Android Studio project
Stars: ✭ 235 (-1.26%)
Mutual labels:  typography
Typetura
Finally, typography as responsive as the web.
Stars: ✭ 208 (-12.61%)
Mutual labels:  typography

Typographizer · Smart Quotes for Swift Apps

Typographizer turns those pesky dumb quotes (""/'') and apostrophes (') into their beautiful, curly, localized counterparts. Because good typography uses smart quotes, not dumb quotes and we should not let the internet kill smart quotes. Speaking of smartness: Typographizer is smart enough to skip HTML tags and everything between certain tags (like <code> and <pre>).

Typographizer has a small footprint, was written in pure Swift, and has been tested on macOS, iOS, watchOS, and tvOS.

I started building Typographizer to typographize Wikipedia articles in my V for Wiki app.

Installation

Put the .swift files into your app’s Xcode project.

How to Use

The easiest way to use Typographizer is the String extension (String+Typographizer.swift):

var s = "This is a string with \"dumb\" quotes."

s = s.typographized(language: "en")

print(s) // This is a string with “dumb” quotes.

Ignoring HTML Tags

If your string may contain HTML, set the isHTML parameter to true. Typographizer will then ignore the quotes inside tags and anything between <pre>, <code>, <var>, <samp>, <kbd>, <math>, <script>, and <style> tags:

var s = "This is a \"string\" with HTML. <code class="">print(\"hello world\")</code>"

s = s.typographized(language: "en", isHTML: true)

print(s) // This is a “string” with HTML. <code class="">print("hello world")</code>

Debug Mode

Activate the debug mode to highlight the characters that have been changed—Typographizer will add this tag around them: <span class="typographizer-debug typographizer-debug--XXX"> </span>

var s = "This is a string with \"dumb\" quotes."

s = s.typographized(language: "en", isHTML: true, debug: true)

print(s) // This is a string with <span class="typographizer-debug typographizer-debug--opening-double">“</span>dumb<span class="typographizer-debug typographizer-debug--closing-double">”</span> quotes.

(Yes, the class names are a little wordy, but that’s on purpose.)

Use CSS to visualize the changes:

.typographizer-debug {
  font-weight: bold;
}

.typographizer-debug--apostrophe {
  color: red;
}

/* … */

Measuring Performance

Pass measurePerformance: true to log performance stats:

s = s.typographized(language: "en", isHTML: true, debug: false, measurePerformance: true)

You’ll see something like this in the Xcode console:

Typographizing took 0.00582303 seconds

Features

  • [x] Fixes double quotes: ""“” (localized)
  • [x] Fixes single quotes: ''‘’ (localized)
  • [x] Fixes apostrophes: '
  • [x] Fixes hyphens that are used as en dashes: … - …… – …
  • [x] Demo app project for macOS

Supported Languages

Language Code Double Quotes Single Quotes Comment
bs
cs
da
de
de_CH « » Swiss Standard German
en
et
fi
fr «\u{00A0} \u{00A0}» ‹\u{00A0} \u{00A0}› French Quotes are set with a non-breaking space (\u{00A0}). A thin non-breaking space would be better, but it’s not supported in most browsers.
hu
is
ja
lt
lv
nl
nn « »
no « »
pl
ro
ru « »
sk
sl
sv

Demo App

To get started, try the included demo app for macOS.

To Do

  • [ ] Handle special cases like ’80s, ’Twas, Rock ’n’ Roll, etc.
  • [ ] Handle primes in coordinates properly:
    52° 27' 20" N, 13° 19' 11" E → 52° 27′ 20″ N, 13° 19′ 11″ E
  • [ ] Add support for Hebrew
  • [ ] If there is only one dumb single quote in a string, it’s probably an apostrophe
  • [ ] Analyze HTML tags to verify correct quotes (opening and closing <p> tags make a good indicator for opening and closing quotation marks)
  • [ ] Track open/closed state while iterating over the text to make more informed decisions
  • [ ] Add more typographic refinements (e.g. prime symbols, thin spaces)

Credits

Typographizer was created by Frank Rausch (@frankrausch).

Thanks to Tony Allevato for the great article on Strings, characters, and performance in Swift—a deep dive.

Contribution Guidelines

Please always use self when accessing methods and properties.

Preferred:

self.coolMethod()

Not preferred:

coolMethod()

License

The Typographizer source code is released under the MIT License. Please view the LICENSE file for details.

The Typographizer logo is © 2017 Frank Rausch; all rights reserved.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].