Skip to content

Commit

Permalink
Line height can now be customised along with font size
Browse files Browse the repository at this point in the history
  • Loading branch information
aramk committed Feb 10, 2013
1 parent f8fdf32 commit fe5e303
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
15 changes: 9 additions & 6 deletions crayon_formatter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ public static function print_code($hl, $code, $line_numbers = TRUE, $print = TRU
// Determine font size
// TODO improve logic
if ($hl->setting_val(CrayonSettings::FONT_SIZE_ENABLE)) {
$font_size = $hl->setting_val(CrayonSettings::FONT_SIZE) . 'px !important;';
$font_height = $font_size * 1.25 . 'px !important;';
$_font_size = $hl->setting_val(CrayonSettings::FONT_SIZE);
$font_size = $_font_size . 'px !important;';
$_line_height = $hl->setting_val(CrayonSettings::LINE_HEIGHT);
// Don't allow line height to be less than font size
$line_height = ($_line_height > $_font_size ? $_line_height : $_font_size) . 'px !important;';
$toolbar_height = $font_size * 1.5 . 'px !important;';
$info_height = $font_size * 1.25 . 'px !important;';
$info_height = $font_size * 1.4 . 'px !important;';

$font_style .= "font-size: $font_size line-height: $font_height";
$font_style .= "font-size: $font_size line-height: $line_height";
$toolbar_style .= "font-size: $font_size";
$line_style .= "height: $font_height";
$line_style .= "height: $line_height";

if ($hl->is_inline()) {
$font_style .= "font-size: $font_size";
Expand All @@ -128,7 +131,7 @@ public static function print_code($hl, $code, $line_numbers = TRUE, $print = TRU
} else if (!$hl->is_inline()) {
if (($font_size = CrayonGlobalSettings::get(CrayonSettings::FONT_SIZE)) !== FALSE) {
$font_size = $font_size->def() . 'px !important;';
$font_height = ($font_size + 4) . 'px !important;';
$line_height = ($font_size * 1.4) . 'px !important;';
}
}

Expand Down
8 changes: 7 additions & 1 deletion crayon_settings.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CrayonSettings {
const FONT = 'font';
const FONT_SIZE_ENABLE = 'font-size-enable';
const FONT_SIZE = 'font-size';
const LINE_HEIGHT = 'line-height';
const PREVIEW = 'preview';
const HEIGHT_SET = 'height-set';
const HEIGHT_MODE = 'height-mode';
Expand Down Expand Up @@ -153,7 +154,8 @@ private function init() {
new CrayonSetting(self::THEME, CrayonThemes::DEFAULT_THEME),
new CrayonSetting(self::FONT, CrayonFonts::DEFAULT_FONT),
new CrayonSetting(self::FONT_SIZE_ENABLE, TRUE),
new CrayonSetting(self::FONT_SIZE, 12),
new CrayonSetting(self::FONT_SIZE, 12),
new CrayonSetting(self::LINE_HEIGHT, 15),
new CrayonSetting(self::PREVIEW, TRUE),
new CrayonSetting(self::HEIGHT_SET, FALSE),
new CrayonSetting(self::HEIGHT_MODE, array(crayon__('Max'), crayon__('Min'), crayon__('Static'))),
Expand Down Expand Up @@ -430,6 +432,10 @@ public static function validate($name, $value) {
$value = 1;
}
break;
case CrayonSettings::LINE_HEIGHT:
$font_size = CrayonGlobalSettings::val(CrayonSettings::FONT_SIZE);
$value = $value >= $font_size ? $value : $font_size;
break;
case CrayonSettings::THEME:
$value = strtolower($value);
// XXX validate settings here
Expand Down
2 changes: 2 additions & 0 deletions crayon_settings_wp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,8 @@ public static function font($editor = FALSE) {
echo '<span class="crayon-span-10"></span>';
self::checkbox(array(CrayonSettings::FONT_SIZE_ENABLE, crayon__('Custom Font Size') . ' '), FALSE);
self::textbox(array('id' => CrayonSettings::FONT_SIZE, 'size' => 2));
echo '<span class="crayon-span-margin">', crayon__('Pixels'), ',&nbsp;&nbsp;',crayon__('Line Height'),' </span>';
self::textbox(array('id' => CrayonSettings::LINE_HEIGHT, 'size' => 2));
echo '<span class="crayon-span-margin">', crayon__('Pixels'), '</span></br>';
if ((!CrayonResources::fonts()->is_loaded($db_font) || !CrayonResources::fonts()->exists($db_font))) {
// Default font doesn't actually exist as a file, it means do not override default theme font
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ It also supports some neat features like:
* Local directory to search for local files
* File extension detection
* Live Preview in settings
* Dimensions, margins, alignment and CSS floating
* Dimensions, margins, alignment, font-size, line-height, float
* Extensive error logging

**Links**
Expand Down Expand Up @@ -153,6 +153,7 @@ These are helpful for discovering new features.

A handful of articles from others written about Crayon, thanks guys!

* <a href="http://www.emanueleferonato.com/2013/02/01/syntax-highlighter-switched-to-crayon/" target="_blank">Syntax highlighter switched to Crayon</a>
* <a href="http://www.wordpressthemeshq.net/5-best-syntax-highlighter-plugins-for-wordpress/" target="_blank">5 Best Syntax Highlighter Plugins for WordPress</a>
* <a href="http://amecylia.com/how-to-post-source-code-wordpress/" target="_blank">How To Post Source Code In Wordpress</a>
* <a href="http://icrunched.co/top-5-syntax-highlighter-wordpress-plugins/" target="_blank">Top 5 Syntax Highlighter WordPress Plugins</a>
Expand Down Expand Up @@ -239,6 +240,8 @@ Contact me at http://twitter.com/crayonsyntax or crayon.syntax@gmail.com.
== Changelog ==

= 2.1.3 =
* ADDED:
* Line height can now be customised along with font size
* FIXED:
* Toolbar font-size and line height improvements

Expand Down

0 comments on commit fe5e303

Please sign in to comment.