Skip to content

Commit

Permalink
Support absolute font sizing in the vertical rhythm module
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Jul 2, 2011
1 parent 94af47d commit 6d2040b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
5 changes: 5 additions & 0 deletions doc-src/content/CHANGELOG.markdown
Expand Up @@ -14,6 +14,11 @@ The Documentation for the [latest stable release](http://compass-style.org/docs/

The Documentation for the [latest preview release](http://beta.compass-style.org/)

0.11.4 (UNRELEASED)
-------------------

* Vertical rhythm now supports absolute units like pixels. Set `$relative-font-sizing` to `false` to enable.

0.11.3 (06/11/2011)
-------------------

Expand Down
Expand Up @@ -10,22 +10,43 @@ $default-rhythm-border-style: solid !default;
// The IE font ratio is a fact of life. Deal with it.
$ie-font-ratio: 16px / 100%;

// Set to false if you want to use absolute pixes in sizing your typography.
$relative-font-sizing: true !default;

// $base-font-size but in your output unit of choice.
// Defaults to 1em when `$relative-font-sizing`
$font-unit: if($relative-font-sizing, 1em, $base-font-size) !default;

// The basic unit of font rhythm
$base-rhythm-unit: $base-line-height / $base-font-size * 1em;
$base-rhythm-unit: $base-line-height / $base-font-size * $font-unit;

// The leader is the amount of whitespace in a line.
// It might be useful in your calculations
$base-leader: ($base-line-height - $base-font-size) * 1em / $base-font-size;
$base-leader: ($base-line-height - $base-font-size) * $font-unit / $base-font-size;

// The half-leader is the amount of whitespace above and below a line.
// It might be useful in your calculations
$base-half-leader: $base-leader / 2;

// True if a number has a relative unit
@function relative-unit($number) {
@return unit($number) == "%" or unit($number) == "em" or unit($number) == "rem"
}

// True if a number has an absolute unit
@function absolute-unit($number) {
@return not (relative-unit($number) or unitless($number));
}

@if $relative-font-sizing and not relative-unit($font-unit) {
@warn "$relative-font-sizing is true but $font-unit is set to #{$font-unit} which is not a relative unit.";
}

// Establishes a font baseline for the given font-size in pixels
@mixin establish-baseline($font-size: $base-font-size) {
body {
font-size: $font-size / $ie-font-ratio;
@include adjust-leading-to(1, $font-size);
@include adjust-leading-to(1, if($relative-font-sizing, $font-size, $base-font-size));
}
html>body {
font-size: $font-size;
Expand All @@ -43,20 +64,29 @@ $base-half-leader: $base-leader / 2;
// to the smallest integer that is large enough to fit the font.
// Use $from_size to adjust from a non-base font-size.
@mixin adjust-font-size-to($to-size, $lines: ceil($to-size / $base-line-height), $from-size: $base-font-size) {
font-size: 1em * $to-size / $from-size;
@include adjust-leading-to($lines, $to-size);
@if $relative-font-sizing and $from-size != $base-font-size {
@warn "$relative-font-sizing is false but a relative font size was passed to adjust-font-size-to";
}
font-size: $font-unit * $to-size / $from-size;
@include adjust-leading-to($lines, if($relative-font-sizing, $to-size, $base-font-size));
}

@mixin adjust-leading-to($lines, $font-size: $base-font-size) {
line-height: 1em * $lines * $base-line-height / $font-size;
@if $relative-font-sizing and $font-size != $base-font-size {
@warn "$relative-font-sizing is false but a relative font size was passed to adjust-leading-to";
}
line-height: $font-unit * $lines * $base-line-height / $font-size;
}

// Calculate rhythm units
@function rhythm(
$lines: 1,
$font-size: $base-font-size
) {
$rhythm: 1em * $lines * $base-line-height / $font-size;
@if $relative-font-sizing and $font-size != $base-font-size {
@warn "$relative-font-sizing is false but a relative font size was passed to the rhythm function";
}
$rhythm: $font-unit * $lines * $base-line-height / $font-size;
@return $rhythm;
}

Expand Down Expand Up @@ -97,19 +127,25 @@ $base-half-leader: $base-leader / 2;

// Apply a border width to any side without destroying the vertical rhythm
@mixin apply-side-rhythm-border($side, $width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
@if $relative-font-sizing and $font-size != $base-font-size {
@warn "$relative-font-sizing is false but a relative font size was passed to apply-side-rhythm-border";
}
border-#{$side}: {
style: $border-style;
width: 1em * $width / $font-size;
width: $font-unit * $width / $font-size;
};
padding-#{$side}: 1em / $font-size * ($lines * $base-line-height - $width);
padding-#{$side}: $font-unit / $font-size * ($lines * $base-line-height - $width);
}

// Aplly rhythm borders equally to all sides
@mixin rhythm-borders($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
@if $relative-font-sizing and $font-size != $base-font-size {
@warn "$relative-font-sizing is false but a relative font size was passed to rhythm-borders";
}
border: {
style: $border-style;
width: 1em * $width / $font-size; };
padding: 1em / $font-size * ($lines * $base-line-height - $width);
width: $font-unit * $width / $font-size; };
padding: $font-unit / $font-size * ($lines * $base-line-height - $width);
}

// Apply a leading rhythm border
Expand Down

0 comments on commit 6d2040b

Please sign in to comment.