Skip to content
This repository

Made defensive resize adjustment relative #25

Open
wants to merge 1 commit into from

2 participants

Mattias Petter Johansson Benjamin Intal
Mattias Petter Johansson
mpj commented

I found that newFontSize turned out slightly off in some cases, 
and I figured that this was due to autoGuessSubtraction being an absolute
number, instead of relative. I honestly have little idea what I'm doing, 
but my fixed solved my problem, at least. :P

Mattias Petter Johansson mpj Made defensive resize adjustment relative
I found that newFontSize turned out slightly off in some cases, 
and I figured that this was due to autoGuessSubtraction being an absolute 
number, instead of relative. I honestly have little idea what I'm doing, 
but my fixed solved my problem, at least. :P
5b91f9a
Benjamin Intal

This has helped me as well especially for small containers with only a few characters:

branch copy of bigtext.js: http://jsfiddle.net/bfintal/RL2JD/1/
adjusted bigtext.js: http://jsfiddle.net/bfintal/WjdAv/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 07, 2012
Mattias Petter Johansson mpj Made defensive resize adjustment relative
I found that newFontSize turned out slightly off in some cases, 
and I figured that this was due to autoGuessSubtraction being an absolute 
number, instead of relative. I honestly have little idea what I'm doing, 
but my fixed solved my problem, at least. :P
5b91f9a
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 10 additions and 11 deletions. Show diff stats Hide diff stats

  1. +10 11 bigtext.js
21 bigtext.js
@@ -77,14 +77,14 @@
77 77 jQueryMethod: function(options)
78 78 {
79 79 BigText.init();
80   -
  80 +
81 81 options = $.extend({
82 82 minfontsize: BigText.DEFAULT_MIN_FONT_SIZE_PX,
83 83 maxfontsize: BigText.DEFAULT_MAX_FONT_SIZE_PX,
84 84 childSelector: '',
85 85 resize: true
86 86 }, options || {});
87   -
  87 +
88 88 return this.each(function()
89 89 {
90 90 var $t = $(this).addClass('bigtext'),
@@ -93,28 +93,28 @@
93 93 BigText.DEFAULT_CHILD_SELECTOR,
94 94 maxWidth = $t.width(),
95 95 id = $t.attr('id');
96   -
  96 +
97 97 if(!id) {
98 98 id = 'bigtext-id' + (counter++);
99 99 $t.attr('id', id);
100 100 }
101   -
  101 +
102 102 if(options.resize) {
103 103 BigText.bindResize('resize.bigtext-event-' + id, function()
104 104 {
105 105 BigText.jQueryMethod.call($('#' + id), options);
106 106 });
107 107 }
108   -
  108 +
109 109 BigText.clearCss(id);
110   -
  110 +
111 111 $t.find(childSelector).addClass(function(lineNumber, className)
112 112 {
113 113 // remove existing line classes.
114 114 return [className.replace(new RegExp('\\b' + BigText.LINE_CLASS_PREFIX + '\\d+\\b'), ''),
115 115 BigText.LINE_CLASS_PREFIX + lineNumber].join(' ');
116 116 });
117   -
  117 +
118 118 var sizes = calculateSizes($t, childSelector, maxWidth, options.maxfontsize, options.minfontsize);
119 119 $headCache.append(BigText.generateCss(id, sizes.fontSizes, sizes.wordSpacings, sizes.minFontSizes));
120 120 });
@@ -185,11 +185,10 @@
185 185 }
186 186
187 187 // TODO we can cache this ratio?
188   - var autoGuessSubtraction = 20, // px
189   - currentFontSize = parseFloat($line.css('font-size')),
  188 + var currentFontSize = parseFloat($line.css('font-size')),
190 189 lineWidth = $line.width(),
191   - ratio = (lineWidth / currentFontSize).toFixed(6),
192   - newFontSize = parseFloat(((maxWidth - autoGuessSubtraction) / ratio).toFixed(3));
  190 + ratio = lineWidth / currentFontSize,
  191 + newFontSize = (maxWidth * 0.94 / ratio).toFixed(3);
193 192
194 193 outer: for(var m=0, n=intervals.length; m<n; m++) {
195 194 inner: for(var j=1, k=4; j<=k; j++) {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.