Code Monkey home page Code Monkey logo

kerning.js's Introduction

Kerning.js

CSS, meet kerning. Kerning, meet CSS. Kern, style, transform, and scale your web type with real CSS rules, automatically.

Kerning.js is a single script, small, and only depends on jQuery. Add it to your page, add some CSS rules, and your text will be beautified.

Status

This project is currently stable. No major issues have been reported.

Version

The current version is 0.2.1.

Usage

Include this file anywhere in your HTML

<script src="kerning.js"></script>

Then, add any of the attributes following to your CSS, under any selectors you want modified:

-letter-kern, -letter-size, -letter-weight, -letter-color, -letter-transform
-word-kern, -word-size, -word-weight, -word-color, -word-transform

To use pairings (e.g., modify 'a' if 'ab' is paired):

-letter-pairs('xy': [value], …)
-word-pairs('cat mouse': [value], …)

To use multiple transforms, you need to use transform "groups":

-transform-group([transform] [transform] …)

To add rules for a particular rendering engine, use a prefix on any of the attributes:

  • Gecko engine (Firefox): -moz
  • Webkit (Chrome, Safari): -webkit
  • Opera: -o
  • Microsoft: -ms

To add rules for a particular operating system, use a prefix on any of the attributes:

  • Windows: -win
  • Mac: -mac
  • Linux: -lin

Note: Do not use a prefix on the attribute values (i.e., -letter-pairs does not need a prefix).

That's it! Attributes will be applied automagically.

Examples

Alter first 3 letters:

-letter-size: 100px 20px 30px;

Modify letter pairs:

-letter-kern: -letter-pairs('ab': 1px,
                            'bc': 300px,
                            's ': 100px);

Transform the first two letters:

-letter-transform: -transform-group(rotate3d(0,0,1,10deg) translate3d(0,10px,0))
                   -transform-group(translate3d(0,-10px,0) rotate3d(0,0,1,-10deg));

Modify word pairs:

-word-size: -word-pairs('this is': 10em);

Modify the first 3 words:

-word-size: 10em 0.1em 0.2em;

WebKit-only:

-webkit-letter-kern: 0 1px 0;

Using repeat rules:

-letter-color: -letter-repeats(even: #f0f0f0, odd: #cccccc);
-letter-color: -letter-repeats(2n+1: #f0f0f0);

Using conditionals:

-letter-kern: if-font('Helvetica Neue': 0 1px 1px, 'Helvetica': 0 -1px 0);

Using conditionals on existing properties for weight or size:

font-size: 9.5em;
font-size: if-font('Helvetica Neue': 10em, 'Helvetica': 9em);

Future

Right now, Kerning.js supports kerning, color, size, weight, and transforms per-letter, per-word, and per-font. In the future, it will include:

  • More compact and refined CSS rules
  • Visual kerning tool with automatic rule generation

License

Copyright 2016 Joshua Gross

MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

kerning.js's People

Contributors

cjgammon avatar endtwist avatar jacobq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kerning.js's Issues

Support for non-webkit browsers?

On which browsers will kerning.js work?
I just now realized that IE8 does not appear to support it.
Including the https://github.com/kriskowal/es5-shim to support Array.prototype.reduce method seems to resolve the script error that it generates, but kerning.js still does not work (page doesn't display "This is Kerning.js" like it does in Chrome and Safari).
image

Firefox (tested version 25) does not appear to be supported either -- same output
image

slow to initialise

Hi

I am doing some svg animations which were loading quick
but since adding this plugin the scripts are being blocked by the kerning module initialising it work but is slow

Can I disable the auto initialisation and manually apply it to an element ?

Thanks
Mark

when parseAttributes = True the script actually reloads the page

this is a killer on dynamic sites. I discovered this only because this was actually causing a session toggle function to toggle twice back to its original state.

simply change

$(document).parsecss(self._parse, true);

to

$(document).parsecss(self._parse, false);

script works fine, doesn't reload page

Toggle Demo

Would love to be able to toggle the demonstrated effects on and off to easily see the difference.

kerning.js breaks kerning pairs

Thanks for providing this library!

I was wondering if there was a way to only insert span elements where actually needed. E.g.

p {
  -letter-kern: -letter-pairs('AV': -0.02em);
}

should only insert span elements for the defined kerning pair.

Currently each letter gets wrapped by a span – which effectively breaks all the native kerning pairs defined by the font file itself (as kerning only happens for adjacent letters).

Using in scss

How are kerning.js css statements meant to be written in .scss files? I'm getting an error output of invalid scss when I compile. Even with --quiet, the file written is still an error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.