Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'leading' font metric for linux platform #1352

Merged
merged 2 commits into from Dec 9, 2013

Conversation

@dhedlund
Copy link
Contributor

dhedlund commented Dec 8, 2013

Fixes #76.

Implemented the only font metric remaining to resolve issue #76 for the Linux platform.

There are still some variations between Linux and OS X font metrics. Looking at values for the "Times New Roman" font, the following metrics differed by over 10%: leading, x_height and max_advance. It was not obvious if this would create any major difference in rendering, or whether the discrepancies would be handled in platform specific ways during the rendering process. Only x_height is being used by existing code. The leading property under Linux is still an order of magnitude off from the OS X version, but they are computed with similar calculations. Issue #1355 has been opened to further investigate the discrepancies.

Platform comparison of font metrics for "Times New Roman" between Linux and OS X:

Au is the raw metric values stored in the FontMetrics struct. % of em is how large that value is relative to the raw em_size of the font as a percentage. Linux reports the pt size differently than OS X, but this is probably because the linux platform uses hard-coded points-per-inch value (hard-coded in src/components/util/geometry.rs), whereas OS X uses the points-per-inch value provided by the font library.

+-----------------------------------+  +-----------------------------------+
| Linux (@14.25pt, 1.33em)          |  | OS X (@19.35pt, 1.0em)            |
+------------------+------+---------+  +------------------+------+---------+
| property         |   Au | % of em |  | property         |   Au | % of em |
+------------------+------+---------+  +------------------+------+---------+
| underline_size   |   55 |    4.82 |  | underline_size   |   60 |    5.17 |
| underline_offset | -151 |  -13.25 |  | underline_offset | -120 |  -10.34 |
| strikeout_size   |   56 |    4.91 |  | strikeout_size   |    0 |    0.00 |
| strikeout_offset |  295 |   25.88 |  | strikeout_offset |    0 |    0.00 |
| leading          |  541 |   47.45 |  | leading          |   60 |    5.17 |
| x_height         | 1015 |   89.04 |  | x_height         |  660 |   56.85 |
| em_size          | 1140 |  100.00 |  | em_size          | 1161 |  100.00 |
| ascent           | 1015 |   89.04 |  | ascent           |  893 |   76.92 |
| descent          |  246 |   21.58 |  | descent          |  203 |   17.48 |
| max_advance      | 1199 |  105.18 |  | max_advance      | 2820 |  242.89 |
+------------------+------+---------+  +------------------+------+---------+

+-----------------------------------+  +-----------------------------------+
| Linux (@24pt, 1.33em)             |  | OS X (@32.683333pt, 1.0em)        |
+------------------+------+---------+  +------------------+------+---------+
| property         |   Au | % of em |  | property         |   Au | % of em |
+------------------+------+---------+  +------------------+------+---------+
| underline_size   |   93 |    4.84 |  | underline_size   |  120 |    6.12 |
| underline_offset | -255 |  -13.28 |  | underline_offset | -240 |  -12.24 |
| strikeout_size   |   95 |    4.95 |  | strikeout_size   |    0 |    0.00 |
| strikeout_offset |  496 |   25.83 |  | strikeout_offset |    0 |    0.00 |
| leading          |  912 |   47.50 |  | leading          |   60 |    3.06 |
| x_height         | 1710 |   89.06 |  | x_height         | 1080 |   55.10 |
| em_size          | 1920 |  100.00 |  | em_size          | 1960 |  100.00 |
| ascent           | 1710 |   89.06 |  | ascent           | 1544 |   78.77 |
| descent          |  415 |   21.61 |  | descent          |  365 |   18.62 |
| max_advance      | 2020 |  105.21 |  | max_advance      | 4740 |  241.84 |
+------------------+------+---------+  +------------------+------+---------+

+-----------------------------------+  +-----------------------------------+
| Linux (@45pt, 1.33em)             |  | OS X (@60.833333pt, 1.0em)        |
+------------------+------+---------+  +------------------+------+---------+
| property         |   Au | % of em |  | property         |   Au | % of em |
+------------------+------+---------+  +------------------+------+---------+
| underline_size   |  175 |    4.86 |  | underline_size   |  180 |    4.93 |
| underline_offset | -479 |  -13.31 |  | underline_offset | -480 |  -13.15 |
| strikeout_size   |  179 |    4.97 |  | strikeout_size   |    0 |    0.00 |
| strikeout_offset |  931 |   25.86 |  | strikeout_offset |    0 |    0.00 |
| leading          | 1709 |   47.47 |  | leading          |  180 |    4.93 |
| x_height         | 3208 |   89.11 |  | x_height         | 2040 |   55.89 |
| em_size          | 3600 |  100.00 |  | em_size          | 3650 |  100.00 |
| ascent           | 3208 |   89.11 |  | ascent           | 2925 |   80.14 |
| descent          |  778 |   21.61 |  | descent          |  690 |   18.90 |
| max_advance      | 3788 |  105.22 |  | max_advance      | 8880 |  243.29 |
+------------------+------+---------+  +------------------+------+---------+

+-----------------------------------+  +-----------------------------------+
| Linux (@30.75pt, 1.33em)          |  | OS X (@41.9pt, 1.0em)             |
+------------------+------+---------+  +------------------+------+---------+
| property         |   Au | % of em |  | property         |   Au | % of em |
+------------------+------+---------+  +------------------+------+---------+
| underline_size   |  120 |    4.88 |  | underline_size   |  120 |    4.77 |
| underline_offset | -327 |  -13.29 |  | underline_offset | -360 |  -14.32 |
| strikeout_size   |  122 |    4.95 |  | strikeout_size   |    0 |    0.00 |
| strikeout_offset |  636 |   25.85 |  | strikeout_offset |    0 |    0.00 |
| leading          | 1168 |   47.47 |  | leading          |  120 |    4.77 |
| x_height         | 2192 |   89.11 |  | x_height         | 1440 |   57.27 |
| em_size          | 2460 |  100.00 |  | em_size          | 2514 |  100.00 |
| ascent           | 2192 |   89.11 |  | ascent           | 1991 |   79.20 |
| descent          |  532 |   21.63 |  | descent          |  487 |   19.37 |
| max_advance      | 2588 |  105.20 |  | max_advance      | 6120 |  243.44 |
+------------------+------+---------+  +------------------+------+---------+
@metajack
Copy link
Contributor

metajack commented Dec 9, 2013

Awesome! Just had the one nit to clean up the history, otherwise r=me.

@dhedlund
Copy link
Contributor Author

dhedlund commented Dec 9, 2013

PR commit list should be cleaned up now.

@jdm

This comment has been minimized.

Copy link

jdm commented on 79789a1 Dec 9, 2013

r=metajack

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented on 79789a1 Dec 9, 2013

saw approval from jdm, metajack
at dhedlund@79789a1

This comment has been minimized.

Copy link
Contributor

bors-servo replied Dec 9, 2013

merging dhedlund/servo/issue_76 = 79789a1 into auto

This comment has been minimized.

Copy link
Contributor

bors-servo replied Dec 9, 2013

dhedlund/servo/issue_76 = 79789a1 merged ok, testing candidate = 1bf28eb

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

bors-servo replied Dec 9, 2013

fast-forwarding master to auto = 1bf28eb

bors-servo pushed a commit that referenced this pull request Dec 9, 2013
Fixes #76.

Implemented the only font metric remaining to resolve issue #76 for the Linux platform.

There are still some variations between Linux and OS X font metrics.  Looking at values for the "Times New Roman" font, the following metrics differed by over 10%:  `leading`, `x_height` and `max_advance`.  It was not obvious if this would create any major difference in rendering, or whether the discrepancies would be handled in platform specific ways during the rendering process.  Only `x_height` is being used by existing code.  The `leading` property under Linux is still an order of magnitude off from the OS X version, but they are computed with similar calculations.  Issue #1355 has been opened to further investigate the discrepancies.

#### Platform comparison of font metrics for "Times New Roman" between Linux and OS X:
**Au** is the raw metric values stored in the `FontMetrics` struct.  **% of em** is how large that value is relative to the raw `em_size` of the font as a percentage.  Linux reports the pt size differently than OS X, but this is probably because the linux platform uses hard-coded points-per-inch value (hard-coded in `src/components/util/geometry.rs`), whereas OS X uses the points-per-inch value provided by the font library.

    +-----------------------------------+  +-----------------------------------+
    | Linux (@14.25pt, 1.33em)          |  | OS X (@19.35pt, 1.0em)            |
    +------------------+------+---------+  +------------------+------+---------+
    | property         |   Au | % of em |  | property         |   Au | % of em |
    +------------------+------+---------+  +------------------+------+---------+
    | underline_size   |   55 |    4.82 |  | underline_size   |   60 |    5.17 |
    | underline_offset | -151 |  -13.25 |  | underline_offset | -120 |  -10.34 |
    | strikeout_size   |   56 |    4.91 |  | strikeout_size   |    0 |    0.00 |
    | strikeout_offset |  295 |   25.88 |  | strikeout_offset |    0 |    0.00 |
    | leading          |  541 |   47.45 |  | leading          |   60 |    5.17 |
    | x_height         | 1015 |   89.04 |  | x_height         |  660 |   56.85 |
    | em_size          | 1140 |  100.00 |  | em_size          | 1161 |  100.00 |
    | ascent           | 1015 |   89.04 |  | ascent           |  893 |   76.92 |
    | descent          |  246 |   21.58 |  | descent          |  203 |   17.48 |
    | max_advance      | 1199 |  105.18 |  | max_advance      | 2820 |  242.89 |
    +------------------+------+---------+  +------------------+------+---------+

    +-----------------------------------+  +-----------------------------------+
    | Linux (@24pt, 1.33em)             |  | OS X (@32.683333pt, 1.0em)        |
    +------------------+------+---------+  +------------------+------+---------+
    | property         |   Au | % of em |  | property         |   Au | % of em |
    +------------------+------+---------+  +------------------+------+---------+
    | underline_size   |   93 |    4.84 |  | underline_size   |  120 |    6.12 |
    | underline_offset | -255 |  -13.28 |  | underline_offset | -240 |  -12.24 |
    | strikeout_size   |   95 |    4.95 |  | strikeout_size   |    0 |    0.00 |
    | strikeout_offset |  496 |   25.83 |  | strikeout_offset |    0 |    0.00 |
    | leading          |  912 |   47.50 |  | leading          |   60 |    3.06 |
    | x_height         | 1710 |   89.06 |  | x_height         | 1080 |   55.10 |
    | em_size          | 1920 |  100.00 |  | em_size          | 1960 |  100.00 |
    | ascent           | 1710 |   89.06 |  | ascent           | 1544 |   78.77 |
    | descent          |  415 |   21.61 |  | descent          |  365 |   18.62 |
    | max_advance      | 2020 |  105.21 |  | max_advance      | 4740 |  241.84 |
    +------------------+------+---------+  +------------------+------+---------+

    +-----------------------------------+  +-----------------------------------+
    | Linux (@45pt, 1.33em)             |  | OS X (@60.833333pt, 1.0em)        |
    +------------------+------+---------+  +------------------+------+---------+
    | property         |   Au | % of em |  | property         |   Au | % of em |
    +------------------+------+---------+  +------------------+------+---------+
    | underline_size   |  175 |    4.86 |  | underline_size   |  180 |    4.93 |
    | underline_offset | -479 |  -13.31 |  | underline_offset | -480 |  -13.15 |
    | strikeout_size   |  179 |    4.97 |  | strikeout_size   |    0 |    0.00 |
    | strikeout_offset |  931 |   25.86 |  | strikeout_offset |    0 |    0.00 |
    | leading          | 1709 |   47.47 |  | leading          |  180 |    4.93 |
    | x_height         | 3208 |   89.11 |  | x_height         | 2040 |   55.89 |
    | em_size          | 3600 |  100.00 |  | em_size          | 3650 |  100.00 |
    | ascent           | 3208 |   89.11 |  | ascent           | 2925 |   80.14 |
    | descent          |  778 |   21.61 |  | descent          |  690 |   18.90 |
    | max_advance      | 3788 |  105.22 |  | max_advance      | 8880 |  243.29 |
    +------------------+------+---------+  +------------------+------+---------+

    +-----------------------------------+  +-----------------------------------+
    | Linux (@30.75pt, 1.33em)          |  | OS X (@41.9pt, 1.0em)             |
    +------------------+------+---------+  +------------------+------+---------+
    | property         |   Au | % of em |  | property         |   Au | % of em |
    +------------------+------+---------+  +------------------+------+---------+
    | underline_size   |  120 |    4.88 |  | underline_size   |  120 |    4.77 |
    | underline_offset | -327 |  -13.29 |  | underline_offset | -360 |  -14.32 |
    | strikeout_size   |  122 |    4.95 |  | strikeout_size   |    0 |    0.00 |
    | strikeout_offset |  636 |   25.85 |  | strikeout_offset |    0 |    0.00 |
    | leading          | 1168 |   47.47 |  | leading          |  120 |    4.77 |
    | x_height         | 2192 |   89.11 |  | x_height         | 1440 |   57.27 |
    | em_size          | 2460 |  100.00 |  | em_size          | 2514 |  100.00 |
    | ascent           | 2192 |   89.11 |  | ascent           | 1991 |   79.20 |
    | descent          |  532 |   21.63 |  | descent          |  487 |   19.37 |
    | max_advance      | 2588 |  105.20 |  | max_advance      | 6120 |  243.44 |
    +------------------+------+---------+  +------------------+------+---------+
@bors-servo bors-servo closed this Dec 9, 2013
@bors-servo bors-servo merged commit 79789a1 into servo:master Dec 9, 2013
1 check passed
1 check passed
default all tests passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.