Skip to content

Commit

Permalink
Improve calculation, fixes bug when fonts get very small in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmarabeas committed Jan 17, 2016
1 parent 302203b commit 815c603
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ng-FitText.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@
, maxFontSize = (attrs.fittextMax === 'initial' ? computed['font-size'] : attrs.fittextMax) || config.max
, lineHeight = computed['line-height']
, display = computed['display']
, calcSize = 10
;

function calculate() {
var ratio = element[0].offsetHeight / element[0].offsetWidth / newlines;
var ratio = (calcSize * newlines) / element[0].offsetWidth / newlines;
return Math.max(
Math.min((parent[0].offsetWidth - 6) * ratio * compressor,
parseFloat(maxFontSize)
Expand All @@ -64,7 +65,7 @@
return;

// Set standard values for calculation
element[0].style.fontSize = '10px';
element[0].style.fontSize = calcSize + 'px';
element[0].style.lineHeight = '1';
element[0].style.display = 'inline-block';

Expand Down

0 comments on commit 815c603

Please sign in to comment.