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

1400 : isVertical(!isHorizontal)
1401 , fontSize(fontSizeInPt * 64.0)
1402{
1404 xHeight = fontSize/2;
1405 capHeight = (fontSize / 5) * 4;
1406
1407 subScriptOffset.second = -(fontSize / 5);
1408 superScriptOffset.second = (fontSize / 3);
1409 if (isHorizontal) {
1412
1413 ascender = (fontSize / 5) * 4;
1415
1417
1421
1422 hangingBaseline = (fontSize / 5) * 3;
1423
1424 caretRun = 0;
1425 caretRise = 1;
1426 caretOffset = 0;
1427
1428 } else {
1431
1432 ascender = fontSize /2;
1434
1438
1440
1441 alphabeticBaseline = ascender - (fontSize / 5) * 4;
1442
1444
1445 caretRun = 1;
1446 caretRise = 0;
1447 caretOffset = 0;
1448 }
1449
1453}
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 1605 of file KoSvgText.cpp.

1606{
1607 qint32 offset = valueForBaselineValue(baseline);
1608 if (offset == 0) return;
1609
1610 alphabeticBaseline -= offset;
1611 hangingBaseline -= offset;
1612 mathematicalBaseline -= offset;
1615 ideographicOverBaseline -= offset;
1616 ideographicCenterBaseline -= offset;
1617 ideographicUnderBaseline -= offset;
1618
1619 ascender -= offset;
1620 descender -= offset;
1621}
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 1455 of file KoSvgText.cpp.

1455 {
1456 return isVertical == other.isVertical
1457 && fontSize == other.fontSize
1458 && zeroAdvance == other.zeroAdvance
1459 && spaceAdvance == other.spaceAdvance
1460 && ideographicAdvance == other.ideographicAdvance
1461 && xHeight == other.xHeight
1462 && capHeight == other.capHeight
1463 && subScriptOffset == other.subScriptOffset
1464 && superScriptOffset == other.superScriptOffset
1465 && ascender == other.ascender
1466 && descender == other.descender
1467 && lineGap == other.lineGap
1468 && alphabeticBaseline == other.alphabeticBaseline
1469 && mathematicalBaseline == other.mathematicalBaseline
1470 && ideographicUnderBaseline == other.ideographicUnderBaseline
1471 && ideographicCenterBaseline == other.ideographicCenterBaseline
1472 && ideographicOverBaseline == other.ideographicOverBaseline
1473 && ideographicFaceUnderBaseline == other.ideographicFaceUnderBaseline
1474 && ideographicFaceOverBaseline == other.ideographicFaceOverBaseline
1475 && hangingBaseline == other.hangingBaseline
1476 && lineThroughOffset == other.lineThroughOffset
1477 && lineThroughThickness == other.lineThroughThickness
1478 && underlineOffset == other.underlineOffset
1479 && underlineThickness == other.underlineThickness
1480 && caretRun == other.caretRun
1481 && caretRise == other.caretRise
1482 && caretOffset == other.caretOffset;
1483}
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 1574 of file KoSvgText.cpp.

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

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 1518 of file KoSvgText.cpp.

1518 {
1519 if (tag == "romn") {
1521 } else if (tag == "hang") {
1523 } else if (tag == "icfb") {
1525 } else if (tag == "icft") {
1527 } else if (tag == "ideo") {
1529 } else if (tag == "idtp") {
1531 } else if (tag == "Idce") {
1533 } else if (tag == "math") {
1535 }
1536}
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 1538 of file KoSvgText.cpp.

1538 {
1539 if (tag == "xhgt") {
1540 xHeight = value;
1541 } else if (tag == "cpht") {
1542 capHeight = value;
1543 } else if (tag == "sbxo") {
1544 subScriptOffset.first = value;
1545 } else if (tag == "sbyo") {
1546 subScriptOffset.second = value;
1547 } else if (tag == "spxo") {
1548 superScriptOffset.first = value;
1549 } else if (tag == "spyo") {
1550 superScriptOffset.second = value;
1551 } else if (tag == "strs") {
1553 } else if (tag == "stro") {
1555 } else if (tag == "unds") {
1557 } else if (tag == "undo") {
1559 } else if (tag == "hcrs") {
1560 caretRise = value;
1561 } else if (tag == "hcrn") {
1562 caretRun = value;
1563 } else if (tag == "hcof") {
1565 } else if (tag == "vcrs") {
1566 caretRise = value;
1567 } else if (tag == "vcrn") {
1568 caretRun = value;
1569 } else if (tag == "vcof") {
1571 }
1572}

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 1485 of file KoSvgText.cpp.

1485 {
1486 qint32 baselineVal = 0;
1487 switch(baseline) {
1489 baselineVal = ideographicUnderBaseline;
1490 break;
1491 case BaselineAlphabetic:
1492 baselineVal = alphabeticBaseline;
1493 break;
1494 case BaselineHanging:
1495 baselineVal = hangingBaseline;
1496 break;
1498 baselineVal = mathematicalBaseline;
1499 break;
1500 case BaselineCentral:
1501 baselineVal = ideographicCenterBaseline;
1502 break;
1503 case BaselineMiddle:
1505 break;
1506 case BaselineTextBottom:
1507 baselineVal = descender;
1508 break;
1509 case BaselineTextTop:
1510 baselineVal = ascender;
1511 break;
1512 default:
1513 break;
1514 }
1515 return baselineVal;
1516}
@ 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

location of alphabetic baseline from origin.

Definition at line 343 of file KoSvgText.h.

◆ ascender

qint32 KoSvgText::FontMetrics::ascender

distance from origin to top.

Definition at line 339 of file KoSvgText.h.

◆ capHeight

qint32 KoSvgText::FontMetrics::capHeight

Height of capital letters, defaults to ascender.

Definition at line 335 of file KoSvgText.h.

◆ caretOffset

qint32 KoSvgText::FontMetrics::caretOffset

Definition at line 364 of file KoSvgText.h.

◆ caretRise

qint32 KoSvgText::FontMetrics::caretRise

Definition at line 363 of file KoSvgText.h.

◆ caretRun

qint32 KoSvgText::FontMetrics::caretRun

These are only used to determine the caret slant proportion.

Definition at line 362 of file KoSvgText.h.

◆ descender

qint32 KoSvgText::FontMetrics::descender

distance for origin to bottom.

Definition at line 340 of file KoSvgText.h.

◆ fontSize

qint32 KoSvgText::FontMetrics::fontSize

Currently set size, CSS unit 'em'.

Definition at line 329 of file KoSvgText.h.

◆ hangingBaseline

qint32 KoSvgText::FontMetrics::hangingBaseline

location of the hanging baseline used in north brahmic scripts.

Definition at line 354 of file KoSvgText.h.

◆ ideographicAdvance

qint32 KoSvgText::FontMetrics::ideographicAdvance

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

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

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

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

location of ideographic over baseline from origin.

Definition at line 349 of file KoSvgText.h.

◆ ideographicUnderBaseline

qint32 KoSvgText::FontMetrics::ideographicUnderBaseline

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

additional linegap between consecutive lines.

Definition at line 341 of file KoSvgText.h.

◆ lineThroughOffset

qint32 KoSvgText::FontMetrics::lineThroughOffset

offset of strike-through from alphabetic baseline.

Definition at line 358 of file KoSvgText.h.

◆ lineThroughThickness

qint32 KoSvgText::FontMetrics::lineThroughThickness

strikethrough thickness, from font.

Definition at line 359 of file KoSvgText.h.

◆ mathematicalBaseline

qint32 KoSvgText::FontMetrics::mathematicalBaseline

location of mathematical baseline from origin.

Definition at line 344 of file KoSvgText.h.

◆ spaceAdvance

qint32 KoSvgText::FontMetrics::spaceAdvance

Advance of the character ' ', used by tabs.

Definition at line 331 of file KoSvgText.h.

◆ subScriptOffset

QPair<qint32, qint32> KoSvgText::FontMetrics::subScriptOffset

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

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

Definition at line 337 of file KoSvgText.h.

◆ underlineOffset

qint32 KoSvgText::FontMetrics::underlineOffset

underline offset from alphabetic, positive.

Definition at line 356 of file KoSvgText.h.

◆ underlineThickness

qint32 KoSvgText::FontMetrics::underlineThickness

underline thickness from font.

Definition at line 357 of file KoSvgText.h.

◆ xHeight

qint32 KoSvgText::FontMetrics::xHeight

height of X, defaults to 0.5 fontsize.

Definition at line 334 of file KoSvgText.h.

◆ zeroAdvance

qint32 KoSvgText::FontMetrics::zeroAdvance

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: