Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgText::FontMetrics Struct Reference

The FontMetrics class A class to keep track of a variety of font metrics. Note that values are in Freetype pixels and coordinates! (that is 64 times bigger than a regular pixel, and Y is swapped.) More...

#include <KoSvgText.h>

+ Inheritance diagram for KoSvgText::FontMetrics:

Public Member Functions

 FontMetrics ()
 
 FontMetrics (qreal fontSizeInPt, bool isHorizontal)
 
void offsetMetricsToNewOrigin (const Baseline baseline)
 
bool operator== (const FontMetrics &other) const
 
void scaleBaselines (const qreal multiplier)
 
void setBaselineValueByTag (const QString &tag, int32_t value)
 
void setMetricsValueByTag (const QLatin1String &tag, int32_t value)
 
int valueForBaselineValue (Baseline baseline) const
 

Public Attributes

qint32 alphabeticBaseline = 0
 location of alphabetic baseline from origin.
 
qint32 ascender = 0
 distance from origin to top.
 
qint32 capHeight = 0
 Height of capital letters, defaults to ascender.
 
qint32 caretOffset = 0
 
qint32 caretRise = 0
 
qint32 caretRun = 0
 These are only used to determine the caret slant proportion.
 
qint32 descender = 0
 distance for origin to bottom.
 
qint32 fontSize = 0
 Currently set size, CSS unit 'em'.
 
qint32 hangingBaseline = 0
 location of the hanging baseline used in north brahmic scripts.
 
qint32 ideographicAdvance = 0
 Advance of the character '水' (U+6C34), CSS Unit ic, defaults to 1 em.
 
qint32 ideographicCenterBaseline = 0
 default baseline for vertical, centered between over and under.
 
qint32 ideographicFaceOverBaseline = 0
 location of ideographic face over baseline, that is, the top of the glyphs.
 
qint32 ideographicFaceUnderBaseline = 0
 location of ideographic face under baseline, that is, the bottom of the glyphs.
 
qint32 ideographicOverBaseline = 0
 location of ideographic over baseline from origin.
 
qint32 ideographicUnderBaseline = 0
 location of ideographic under baseline from origin, may fall back to descender.
 
bool isVertical = false
 Different fontMetrics count between vertical and horizontal.
 
qint32 lineGap = 0
 additional linegap between consecutive lines.
 
qint32 lineThroughOffset = 0
 offset of strike-through from alphabetic baseline.
 
qint32 lineThroughThickness = 0
 strikethrough thickness, from font.
 
qint32 mathematicalBaseline = 0
 location of mathematical baseline from origin.
 
qint32 spaceAdvance = 0
 Advance of the character ' ', used by tabs.
 
QPair< qint32, qint32 > subScriptOffset = qMakePair(0, 0)
 subscript baseline height, defaults to 1/5th em below alphabetic.
 
QPair< qint32, qint32 > superScriptOffset = qMakePair(0, 0)
 superscript baseline height, defaults to 2/3rd above alphabetic.
 
qint32 underlineOffset = 0
 underline offset from alphabetic, positive.
 
qint32 underlineThickness = 0
 underline thickness from font.
 
qint32 xHeight = 0
 height of X, defaults to 0.5 fontsize.
 
qint32 zeroAdvance = 0
 Advance of the character '0', CSS Unit 'ch', defaults to 0.5 em in horizontal and 1.0 em in vertical.
 

Detailed Description

The FontMetrics class A class to keep track of a variety of font metrics. Note that values are in Freetype pixels and coordinates! (that is 64 times bigger than a regular pixel, and Y is swapped.)

Definition at line 327 of file KoSvgText.h.

Constructor & Destructor Documentation

◆ FontMetrics() [1/2]

KoSvgText::FontMetrics::FontMetrics ( )
inline

Definition at line 366 of file KoSvgText.h.

366 {
367
368 }

◆ FontMetrics() [2/2]

KoSvgText::FontMetrics::FontMetrics ( qreal fontSizeInPt,
bool isHorizontal )

Definition at line 1405 of file KoSvgText.cpp.

1406 : isVertical(!isHorizontal)
1407 , fontSize(fontSizeInPt * 64.0)
1408{
1410 xHeight = fontSize/2;
1411 capHeight = (fontSize / 5) * 4;
1412
1413 subScriptOffset.second = -(fontSize / 5);
1414 superScriptOffset.second = (fontSize / 3);
1415 if (isHorizontal) {
1418
1419 ascender = (fontSize / 5) * 4;
1421
1423
1427
1428 hangingBaseline = (fontSize / 5) * 3;
1429
1430 caretRun = 0;
1431 caretRise = 1;
1432 caretOffset = 0;
1433
1434 } else {
1437
1438 ascender = fontSize /2;
1440
1444
1446
1447 alphabeticBaseline = ascender - (fontSize / 5) * 4;
1448
1450
1451 caretRun = 1;
1452 caretRise = 0;
1453 caretOffset = 0;
1454 }
1455
1459}
qint32 ideographicCenterBaseline
default baseline for vertical, centered between over and under.
Definition KoSvgText.h:347
qint32 ideographicUnderBaseline
location of ideographic under baseline from origin, may fall back to descender.
Definition KoSvgText.h:346
QPair< qint32, qint32 > subScriptOffset
subscript baseline height, defaults to 1/5th em below alphabetic.
Definition KoSvgText.h:336
qint32 xHeight
height of X, defaults to 0.5 fontsize.
Definition KoSvgText.h:334
qint32 lineThroughOffset
offset of strike-through from alphabetic baseline.
Definition KoSvgText.h:358
qint32 zeroAdvance
Advance of the character '0', CSS Unit 'ch', defaults to 0.5 em in horizontal and 1....
Definition KoSvgText.h:330
qint32 ideographicAdvance
Advance of the character '水' (U+6C34), CSS Unit ic, defaults to 1 em.
Definition KoSvgText.h:332
qint32 ideographicFaceOverBaseline
location of ideographic face over baseline, that is, the top of the glyphs.
Definition KoSvgText.h:352
qint32 ideographicOverBaseline
location of ideographic over baseline from origin.
Definition KoSvgText.h:349
qint32 fontSize
Currently set size, CSS unit 'em'.
Definition KoSvgText.h:329
qint32 ideographicFaceUnderBaseline
location of ideographic face under baseline, that is, the bottom of the glyphs.
Definition KoSvgText.h:351
qint32 caretRun
These are only used to determine the caret slant proportion.
Definition KoSvgText.h:362
qint32 alphabeticBaseline
location of alphabetic baseline from origin.
Definition KoSvgText.h:343
qint32 descender
distance for origin to bottom.
Definition KoSvgText.h:340
qint32 ascender
distance from origin to top.
Definition KoSvgText.h:339
qint32 mathematicalBaseline
location of mathematical baseline from origin.
Definition KoSvgText.h:344
qint32 capHeight
Height of capital letters, defaults to ascender.
Definition KoSvgText.h:335
bool isVertical
Different fontMetrics count between vertical and horizontal.
Definition KoSvgText.h:328
qint32 hangingBaseline
location of the hanging baseline used in north brahmic scripts.
Definition KoSvgText.h:354
qint32 spaceAdvance
Advance of the character ' ', used by tabs.
Definition KoSvgText.h:331
QPair< qint32, qint32 > superScriptOffset
superscript baseline height, defaults to 2/3rd above alphabetic.
Definition KoSvgText.h:337

References alphabeticBaseline, ascender, capHeight, caretOffset, caretRise, caretRun, descender, fontSize, hangingBaseline, ideographicAdvance, ideographicCenterBaseline, ideographicFaceOverBaseline, ideographicFaceUnderBaseline, ideographicOverBaseline, ideographicUnderBaseline, lineThroughOffset, mathematicalBaseline, spaceAdvance, subScriptOffset, superScriptOffset, xHeight, and zeroAdvance.

Member Function Documentation

◆ offsetMetricsToNewOrigin()

void KoSvgText::FontMetrics::offsetMetricsToNewOrigin ( const Baseline baseline)

Definition at line 1611 of file KoSvgText.cpp.

1612{
1613 qint32 offset = valueForBaselineValue(baseline);
1614 if (offset == 0) return;
1615
1616 alphabeticBaseline -= offset;
1617 hangingBaseline -= offset;
1618 mathematicalBaseline -= offset;
1621 ideographicOverBaseline -= offset;
1622 ideographicCenterBaseline -= offset;
1623 ideographicUnderBaseline -= offset;
1624
1625 ascender -= offset;
1626 descender -= offset;
1627}
int valueForBaselineValue(Baseline baseline) const

References alphabeticBaseline, ascender, descender, hangingBaseline, ideographicCenterBaseline, ideographicFaceOverBaseline, ideographicFaceUnderBaseline, ideographicOverBaseline, ideographicUnderBaseline, mathematicalBaseline, and valueForBaselineValue().

◆ operator==()

bool KoSvgText::FontMetrics::operator== ( const FontMetrics & other) const

Definition at line 1461 of file KoSvgText.cpp.

1461 {
1462 return isVertical == other.isVertical
1463 && fontSize == other.fontSize
1464 && zeroAdvance == other.zeroAdvance
1465 && spaceAdvance == other.spaceAdvance
1466 && ideographicAdvance == other.ideographicAdvance
1467 && xHeight == other.xHeight
1468 && capHeight == other.capHeight
1469 && subScriptOffset == other.subScriptOffset
1470 && superScriptOffset == other.superScriptOffset
1471 && ascender == other.ascender
1472 && descender == other.descender
1473 && lineGap == other.lineGap
1474 && alphabeticBaseline == other.alphabeticBaseline
1475 && mathematicalBaseline == other.mathematicalBaseline
1476 && ideographicUnderBaseline == other.ideographicUnderBaseline
1477 && ideographicCenterBaseline == other.ideographicCenterBaseline
1478 && ideographicOverBaseline == other.ideographicOverBaseline
1479 && ideographicFaceUnderBaseline == other.ideographicFaceUnderBaseline
1480 && ideographicFaceOverBaseline == other.ideographicFaceOverBaseline
1481 && hangingBaseline == other.hangingBaseline
1482 && lineThroughOffset == other.lineThroughOffset
1483 && lineThroughThickness == other.lineThroughThickness
1484 && underlineOffset == other.underlineOffset
1485 && underlineThickness == other.underlineThickness
1486 && caretRun == other.caretRun
1487 && caretRise == other.caretRise
1488 && caretOffset == other.caretOffset;
1489}
qint32 lineThroughThickness
strikethrough thickness, from font.
Definition KoSvgText.h:359
qint32 underlineThickness
underline thickness from font.
Definition KoSvgText.h:357
qint32 lineGap
additional linegap between consecutive lines.
Definition KoSvgText.h:341
qint32 underlineOffset
underline offset from alphabetic, positive.
Definition KoSvgText.h:356

References alphabeticBaseline, ascender, capHeight, caretOffset, caretRise, caretRun, descender, fontSize, hangingBaseline, ideographicAdvance, ideographicCenterBaseline, ideographicFaceOverBaseline, ideographicFaceUnderBaseline, ideographicOverBaseline, ideographicUnderBaseline, isVertical, lineGap, lineThroughOffset, lineThroughThickness, mathematicalBaseline, spaceAdvance, subScriptOffset, superScriptOffset, underlineOffset, underlineThickness, xHeight, and zeroAdvance.

◆ scaleBaselines()

void KoSvgText::FontMetrics::scaleBaselines ( const qreal multiplier)

Definition at line 1580 of file KoSvgText.cpp.

1581{
1582 alphabeticBaseline *= multiplier;
1583 hangingBaseline *= multiplier;
1584 mathematicalBaseline *= multiplier;
1585 ideographicFaceUnderBaseline *= multiplier;
1586 ideographicFaceOverBaseline *= multiplier;
1587 ideographicOverBaseline *= multiplier;
1588 ideographicCenterBaseline *= multiplier;
1589 ideographicUnderBaseline *= multiplier;
1590 xHeight *= multiplier;
1591 capHeight *= multiplier;
1592 subScriptOffset.first *= multiplier;
1593 subScriptOffset.second *= multiplier;
1594 superScriptOffset.first *= multiplier;
1595 superScriptOffset.second *= multiplier;
1596 fontSize *= multiplier;
1597 ascender *= multiplier;
1598 descender *= multiplier;
1599 lineGap *= multiplier;
1600
1601 zeroAdvance *= multiplier;
1602 spaceAdvance *= multiplier;
1603 ideographicAdvance *= multiplier;
1604
1605 underlineOffset *= multiplier;
1606 underlineThickness *= multiplier;
1607 lineThroughOffset *= multiplier;
1608 lineThroughThickness *= multiplier;
1609}

References alphabeticBaseline, ascender, capHeight, descender, fontSize, hangingBaseline, ideographicAdvance, ideographicCenterBaseline, ideographicFaceOverBaseline, ideographicFaceUnderBaseline, ideographicOverBaseline, ideographicUnderBaseline, lineGap, lineThroughOffset, lineThroughThickness, mathematicalBaseline, spaceAdvance, subScriptOffset, superScriptOffset, underlineOffset, underlineThickness, xHeight, and zeroAdvance.

◆ setBaselineValueByTag()

void KoSvgText::FontMetrics::setBaselineValueByTag ( const QString & tag,
int32_t value )

Definition at line 1524 of file KoSvgText.cpp.

1524 {
1525 if (tag == "romn") {
1527 } else if (tag == "hang") {
1529 } else if (tag == "icfb") {
1531 } else if (tag == "icft") {
1533 } else if (tag == "ideo") {
1535 } else if (tag == "idtp") {
1537 } else if (tag == "Idce") {
1539 } else if (tag == "math") {
1541 }
1542}
float value(const T *src, size_t ch)

References alphabeticBaseline, hangingBaseline, ideographicCenterBaseline, ideographicFaceOverBaseline, ideographicFaceUnderBaseline, ideographicOverBaseline, ideographicUnderBaseline, mathematicalBaseline, and value().

◆ setMetricsValueByTag()

void KoSvgText::FontMetrics::setMetricsValueByTag ( const QLatin1String & tag,
int32_t value )

Definition at line 1544 of file KoSvgText.cpp.

1544 {
1545 if (tag == "xhgt") {
1546 xHeight = value;
1547 } else if (tag == "cpht") {
1548 capHeight = value;
1549 } else if (tag == "sbxo") {
1550 subScriptOffset.first = value;
1551 } else if (tag == "sbyo") {
1552 subScriptOffset.second = value;
1553 } else if (tag == "spxo") {
1554 superScriptOffset.first = value;
1555 } else if (tag == "spyo") {
1556 superScriptOffset.second = value;
1557 } else if (tag == "strs") {
1559 } else if (tag == "stro") {
1561 } else if (tag == "unds") {
1563 } else if (tag == "undo") {
1565 } else if (tag == "hcrs") {
1566 caretRise = value;
1567 } else if (tag == "hcrn") {
1568 caretRun = value;
1569 } else if (tag == "hcof") {
1571 } else if (tag == "vcrs") {
1572 caretRise = value;
1573 } else if (tag == "vcrn") {
1574 caretRun = value;
1575 } else if (tag == "vcof") {
1577 }
1578}

References capHeight, caretOffset, caretRise, caretRun, lineThroughOffset, lineThroughThickness, subScriptOffset, superScriptOffset, underlineOffset, underlineThickness, value(), and xHeight.

◆ valueForBaselineValue()

int KoSvgText::FontMetrics::valueForBaselineValue ( Baseline baseline) const

Definition at line 1491 of file KoSvgText.cpp.

1491 {
1492 qint32 baselineVal = 0;
1493 switch(baseline) {
1495 baselineVal = ideographicUnderBaseline;
1496 break;
1497 case BaselineAlphabetic:
1498 baselineVal = alphabeticBaseline;
1499 break;
1500 case BaselineHanging:
1501 baselineVal = hangingBaseline;
1502 break;
1504 baselineVal = mathematicalBaseline;
1505 break;
1506 case BaselineCentral:
1507 baselineVal = ideographicCenterBaseline;
1508 break;
1509 case BaselineMiddle:
1511 break;
1512 case BaselineTextBottom:
1513 baselineVal = descender;
1514 break;
1515 case BaselineTextTop:
1516 baselineVal = ascender;
1517 break;
1518 default:
1519 break;
1520 }
1521 return baselineVal;
1522}
@ BaselineAlphabetic
Use 'romn' or the baseline for LCG scripts.
Definition KoSvgText.h:225
@ BaselineHanging
Definition KoSvgText.h:226
@ BaselineMiddle
Definition KoSvgText.h:232
@ BaselineTextBottom
Bottom side of the inline line-box.
Definition KoSvgText.h:234
@ BaselineIdeographic
Definition KoSvgText.h:223
@ BaselineMathematical
Definition KoSvgText.h:228
@ BaselineTextTop
Top side of the inline line-box.
Definition KoSvgText.h:235
@ BaselineCentral
Use the center between the ideographic over and under.
Definition KoSvgText.h:231

References alphabeticBaseline, ascender, KoSvgText::BaselineAlphabetic, KoSvgText::BaselineCentral, KoSvgText::BaselineHanging, KoSvgText::BaselineIdeographic, KoSvgText::BaselineMathematical, KoSvgText::BaselineMiddle, KoSvgText::BaselineTextBottom, KoSvgText::BaselineTextTop, descender, hangingBaseline, ideographicCenterBaseline, ideographicUnderBaseline, isVertical, mathematicalBaseline, and xHeight.

Member Data Documentation

◆ alphabeticBaseline

qint32 KoSvgText::FontMetrics::alphabeticBaseline = 0

location of alphabetic baseline from origin.

Definition at line 343 of file KoSvgText.h.

◆ ascender

qint32 KoSvgText::FontMetrics::ascender = 0

distance from origin to top.

Definition at line 339 of file KoSvgText.h.

◆ capHeight

qint32 KoSvgText::FontMetrics::capHeight = 0

Height of capital letters, defaults to ascender.

Definition at line 335 of file KoSvgText.h.

◆ caretOffset

qint32 KoSvgText::FontMetrics::caretOffset = 0

Definition at line 364 of file KoSvgText.h.

◆ caretRise

qint32 KoSvgText::FontMetrics::caretRise = 0

Definition at line 363 of file KoSvgText.h.

◆ caretRun

qint32 KoSvgText::FontMetrics::caretRun = 0

These are only used to determine the caret slant proportion.

Definition at line 362 of file KoSvgText.h.

◆ descender

qint32 KoSvgText::FontMetrics::descender = 0

distance for origin to bottom.

Definition at line 340 of file KoSvgText.h.

◆ fontSize

qint32 KoSvgText::FontMetrics::fontSize = 0

Currently set size, CSS unit 'em'.

Definition at line 329 of file KoSvgText.h.

◆ hangingBaseline

qint32 KoSvgText::FontMetrics::hangingBaseline = 0

location of the hanging baseline used in north brahmic scripts.

Definition at line 354 of file KoSvgText.h.

◆ ideographicAdvance

qint32 KoSvgText::FontMetrics::ideographicAdvance = 0

Advance of the character '水' (U+6C34), CSS Unit ic, defaults to 1 em.

Definition at line 332 of file KoSvgText.h.

◆ ideographicCenterBaseline

qint32 KoSvgText::FontMetrics::ideographicCenterBaseline = 0

default baseline for vertical, centered between over and under.

location of ideographic center baseline from origin,

Definition at line 347 of file KoSvgText.h.

◆ ideographicFaceOverBaseline

qint32 KoSvgText::FontMetrics::ideographicFaceOverBaseline = 0

location of ideographic face over baseline, that is, the top of the glyphs.

Definition at line 352 of file KoSvgText.h.

◆ ideographicFaceUnderBaseline

qint32 KoSvgText::FontMetrics::ideographicFaceUnderBaseline = 0

location of ideographic face under baseline, that is, the bottom of the glyphs.

Definition at line 351 of file KoSvgText.h.

◆ ideographicOverBaseline

qint32 KoSvgText::FontMetrics::ideographicOverBaseline = 0

location of ideographic over baseline from origin.

Definition at line 349 of file KoSvgText.h.

◆ ideographicUnderBaseline

qint32 KoSvgText::FontMetrics::ideographicUnderBaseline = 0

location of ideographic under baseline from origin, may fall back to descender.

Definition at line 346 of file KoSvgText.h.

◆ isVertical

bool KoSvgText::FontMetrics::isVertical = false

Different fontMetrics count between vertical and horizontal.

Definition at line 328 of file KoSvgText.h.

◆ lineGap

qint32 KoSvgText::FontMetrics::lineGap = 0

additional linegap between consecutive lines.

Definition at line 341 of file KoSvgText.h.

◆ lineThroughOffset

qint32 KoSvgText::FontMetrics::lineThroughOffset = 0

offset of strike-through from alphabetic baseline.

Definition at line 358 of file KoSvgText.h.

◆ lineThroughThickness

qint32 KoSvgText::FontMetrics::lineThroughThickness = 0

strikethrough thickness, from font.

Definition at line 359 of file KoSvgText.h.

◆ mathematicalBaseline

qint32 KoSvgText::FontMetrics::mathematicalBaseline = 0

location of mathematical baseline from origin.

Definition at line 344 of file KoSvgText.h.

◆ spaceAdvance

qint32 KoSvgText::FontMetrics::spaceAdvance = 0

Advance of the character ' ', used by tabs.

Definition at line 331 of file KoSvgText.h.

◆ subScriptOffset

QPair<qint32, qint32> KoSvgText::FontMetrics::subScriptOffset = qMakePair(0, 0)

subscript baseline height, defaults to 1/5th em below alphabetic.

Definition at line 336 of file KoSvgText.h.

◆ superScriptOffset

QPair<qint32, qint32> KoSvgText::FontMetrics::superScriptOffset = qMakePair(0, 0)

superscript baseline height, defaults to 2/3rd above alphabetic.

Definition at line 337 of file KoSvgText.h.

◆ underlineOffset

qint32 KoSvgText::FontMetrics::underlineOffset = 0

underline offset from alphabetic, positive.

Definition at line 356 of file KoSvgText.h.

◆ underlineThickness

qint32 KoSvgText::FontMetrics::underlineThickness = 0

underline thickness from font.

Definition at line 357 of file KoSvgText.h.

◆ xHeight

qint32 KoSvgText::FontMetrics::xHeight = 0

height of X, defaults to 0.5 fontsize.

Definition at line 334 of file KoSvgText.h.

◆ zeroAdvance

qint32 KoSvgText::FontMetrics::zeroAdvance = 0

Advance of the character '0', CSS Unit 'ch', defaults to 0.5 em in horizontal and 1.0 em in vertical.

Definition at line 330 of file KoSvgText.h.


The documentation for this struct was generated from the following files: