Ensure there is a minimum of padding in each line when calculating how many lines are needed.

This commit is contained in:
Chris Eppstein 2011-07-01 21:41:35 -07:00
parent 6d2040b86a
commit 157c2e0518

View File

@ -13,6 +13,10 @@ $ie-font-ratio: 16px / 100%;
// Set to false if you want to use absolute pixes in sizing your typography. // Set to false if you want to use absolute pixes in sizing your typography.
$relative-font-sizing: true !default; $relative-font-sizing: true !default;
// Ensure there is at least this many pixels
// of vertical padding above and below the text.
$min-line-padding: 2px;
// $base-font-size but in your output unit of choice. // $base-font-size but in your output unit of choice.
// Defaults to 1em when `$relative-font-sizing` // Defaults to 1em when `$relative-font-sizing`
$font-unit: if($relative-font-sizing, 1em, $base-font-size) !default; $font-unit: if($relative-font-sizing, 1em, $base-font-size) !default;
@ -63,7 +67,7 @@ $base-half-leader: $base-leader / 2;
// font size should use up. Does not have to be an integer, but it defaults // font size should use up. Does not have to be an integer, but it defaults
// to the smallest integer that is large enough to fit the font. // to the smallest integer that is large enough to fit the font.
// Use $from_size to adjust from a non-base font-size. // 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) { @mixin adjust-font-size-to($to-size, $lines: lines-for-font-size($to-size), $from-size: $base-font-size) {
@if $relative-font-sizing and $from-size != $base-font-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"; @warn "$relative-font-sizing is false but a relative font size was passed to adjust-font-size-to";
} }
@ -90,6 +94,14 @@ $base-half-leader: $base-leader / 2;
@return $rhythm; @return $rhythm;
} }
@function lines-for-font-size($font-size) {
$lines: ceil($font-size / $base-line-height);
@if $lines * $base-line-height - $font-size < $min-line-padding * 2 {
$lines: $lines + 1;
}
@return $lines;
}
// Apply leading whitespace // Apply leading whitespace
@mixin leader($lines: 1, $font-size: $base-font-size, $property: margin) { @mixin leader($lines: 1, $font-size: $base-font-size, $property: margin) {
#{$property}-top: rhythm($lines, $font-size); #{$property}-top: rhythm($lines, $font-size);