Changeset 126438 in webkit


Ignore:
Timestamp:
Aug 23, 2012 9:24:15 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Text Autosizing: Multiply large fonts less, as they are already more legible.
https://bugs.webkit.org/show_bug.cgi?id=94227

Patch by John Mellor <johnme@chromium.org> on 2012-08-23
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Rather than uniformly multiplying font sizes by the multiplier (derived
from the width of the block), we should multiply fonts that are already
large less, since they are already more legible hence there is less need
for them to grow.

However it is still important to maintain differentiation between text
that the author specified to be of different sizes.

This algorithm multiplies text by the multiplier up until a predefined
"pleasant" font size; beyond that the computedSize goes up with
specifiedSize but at a gradient of less than 1 in order to gradually
fade out the size increase; finally for very large specifiedSizes the
computedSize will be the same as the specifiedSize.

For further details, including a graph, please see the bug report.

Test: fast/text-autosizing/various-font-sizes.html

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::computeAutosizedFontSize):

Implements the custom multiplication. See comment for details.

  • rendering/style/RenderStyle.cpp:

(WebCore::RenderStyle::lineHeight):

Use computeAutosizedFontSize instead of directly multiplying.

(WebCore::RenderStyle::setFontSize):

Use computeAutosizedFontSize instead of directly multiplying.

LayoutTests:

Added test demonstrating how various font sizes are affected.

  • fast/text-autosizing/various-font-sizes-expected.html: Added.
  • fast/text-autosizing/various-font-sizes.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r126417 r126438  
     12012-08-23  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Multiply large fonts less, as they are already more legible.
     4        https://bugs.webkit.org/show_bug.cgi?id=94227
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Added test demonstrating how various font sizes are affected.
     9
     10        * fast/text-autosizing/various-font-sizes-expected.html: Added.
     11        * fast/text-autosizing/various-font-sizes.html: Added.
     12
    1132012-08-23  Zan Dobersek  <zandobersek@gmail.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r126437 r126438  
     12012-08-23  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Multiply large fonts less, as they are already more legible.
     4        https://bugs.webkit.org/show_bug.cgi?id=94227
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Rather than uniformly multiplying font sizes by the multiplier (derived
     9        from the width of the block), we should multiply fonts that are already
     10        large less, since they are already more legible hence there is less need
     11        for them to grow.
     12
     13        However it is still important to maintain differentiation between text
     14        that the author specified to be of different sizes.
     15
     16        This algorithm multiplies text by the multiplier up until a predefined
     17        "pleasant" font size; beyond that the computedSize goes up with
     18        specifiedSize but at a gradient of less than 1 in order to gradually
     19        fade out the size increase; finally for very large specifiedSizes the
     20        computedSize will be the same as the specifiedSize.
     21
     22        For further details, including a graph, please see the bug report.
     23
     24        Test: fast/text-autosizing/various-font-sizes.html
     25
     26        * rendering/TextAutosizer.cpp:
     27        (WebCore::TextAutosizer::computeAutosizedFontSize):
     28
     29            Implements the custom multiplication. See comment for details.
     30
     31        * rendering/style/RenderStyle.cpp:
     32        (WebCore::RenderStyle::lineHeight):
     33
     34            Use computeAutosizedFontSize instead of directly multiplying.
     35
     36        (WebCore::RenderStyle::setFontSize):
     37
     38            Use computeAutosizedFontSize instead of directly multiplying.
     39
    1402012-08-23  Emil A Eklund  <eae@chromium.org>
    241
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r126359 r126438  
    108108}
    109109
     110float TextAutosizer::computeAutosizedFontSize(float specifiedSize, float multiplier)
     111{
     112    // Somewhat arbitrary "pleasant" font size.
     113    const float pleasantSize = 16;
     114
     115    // Multiply fonts that the page author has specified to be larger than
     116    // pleasantSize by less and less, until huge fonts are not increased at all.
     117    // For specifiedSize between 0 and pleasantSize we directly apply the
     118    // multiplier; hence for specifiedSize == pleasantSize, computedSize will be
     119    // multiplier * pleasantSize. For greater specifiedSizes we want to
     120    // gradually fade out the multiplier, so for every 1px increase in
     121    // specifiedSize beyond pleasantSize we will only increase computedSize
     122    // by gradientAfterPleasantSize px until we meet the
     123    // computedSize = specifiedSize line, after which we stay on that line (so
     124    // then every 1px increase in specifiedSize increases computedSize by 1px).
     125    const float gradientAfterPleasantSize = 0.5;
     126
     127    float computedSize;
     128    if (specifiedSize <= pleasantSize)
     129        computedSize = multiplier * specifiedSize;
     130    else {
     131        computedSize = multiplier * pleasantSize + gradientAfterPleasantSize * (specifiedSize - pleasantSize);
     132        if (computedSize < specifiedSize)
     133            computedSize = specifiedSize;
     134    }
     135    return computedSize;
     136}
     137
    110138bool TextAutosizer::isNotAnAutosizingContainer(const RenderObject* renderer)
    111139{
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r126058 r126438  
    5252    bool processSubtree(RenderObject* layoutRoot);
    5353
     54    static float computeAutosizedFontSize(float specifiedSize, float multiplier);
     55
    5456private:
    5557    explicit TextAutosizer(Document*);
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r126359 r126438  
    4343#include <wtf/StdLibExtras.h>
    4444#include <algorithm>
     45
     46#if ENABLE(TEXT_AUTOSIZING)
     47#include "TextAutosizer.h"
     48#endif
    4549
    4650using namespace std;
     
    12241228    float multiplier = textAutosizingMultiplier();
    12251229    if (multiplier > 1 && lh.isFixed())
    1226         return Length(lh.value() * multiplier, Fixed);
     1230        return Length(TextAutosizer::computeAutosizedFontSize(lh.value(), multiplier), Fixed);
    12271231#endif
    12281232    return lh;
     
    12631267    float multiplier = textAutosizingMultiplier();
    12641268    if (multiplier > 1) {
    1265         // FIXME: Large font sizes needn't be multiplied as much since they are already more legible.
    1266         desc.setComputedSize(size * multiplier);
     1269        desc.setComputedSize(TextAutosizer::computeAutosizedFontSize(size, multiplier));
    12671270    }
    12681271#endif
Note: See TracChangeset for help on using the changeset viewer.