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

The ResolutionHandler class. More...

#include <KoSvgText.h>

Public Member Functions

QPointF adjust (const QPointF point) const
 Adjusts the point to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVertical are true.
 
QRectF adjust (const QRectF rect) const
 Adjusts the rect to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVertical are true.
 
QPointF adjustCeil (const QPointF point) const
 Adjusts the point to ceiled pixel values.
 
QPointF adjustFloor (const QPointF point) const
 Adjusts the point to floored pixel values.
 
QPointF adjustWithOffset (const QPointF point, const QPointF offset) const
 
qreal freeTypePixelToPointFactor (const bool x=true) const
 
QTransform freeTypeToPixelTransform () const
 
QTransform freeTypeToPointTransform () const
 
QTransform pixelToPoint () const
 
qreal pixelToPointFactor (const bool x=true) const
 
QTransform pointToPixel () const
 
qreal pointToPixelFactor (const bool x=true) const
 
 ResolutionHandler (qreal _xRes=72.0, qreal _yRes=72.0, bool _roundToPixelHorizontal=false, bool _roundToPixelVertical=false)
 

Public Attributes

const qreal freeTypePixel = 64.0
 
const qreal pointInInch = 72.0
 
bool roundToPixelHorizontal = false
 
bool roundToPixelVertical = false
 
qreal xRes = 72.0
 
qreal yRes = 72.0
 

Detailed Description

The ResolutionHandler class.

convenience struct to handle all the conversions between pixels and points and freetype pixels.

Definition at line 1084 of file KoSvgText.h.

Constructor & Destructor Documentation

◆ ResolutionHandler()

KoSvgText::ResolutionHandler::ResolutionHandler ( qreal _xRes = 72.0,
qreal _yRes = 72.0,
bool _roundToPixelHorizontal = false,
bool _roundToPixelVertical = false )
inline

Definition at line 1086 of file KoSvgText.h.

1087 : xRes(_xRes), yRes(_yRes), roundToPixelHorizontal(_roundToPixelHorizontal), roundToPixelVertical(_roundToPixelVertical) {}

Member Function Documentation

◆ adjust() [1/2]

QPointF KoSvgText::ResolutionHandler::adjust ( const QPointF point) const

Adjusts the point to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVertical are true.

Definition at line 1710 of file KoSvgText.cpp.

1710 {
1711 if (!roundToPixelHorizontal && !roundToPixelVertical) return point;
1712 QPointF pix = pointToPixel().map(point);
1714 pix.setX(qRound(pix.x()));
1715 }
1717 pix.setY(qRound(pix.y()));
1718 }
1719 return pixelToPoint().map(pix);
1720}
QTransform pixelToPoint() const
QTransform pointToPixel() const

References pixelToPoint(), pointToPixel(), roundToPixelHorizontal, and roundToPixelVertical.

◆ adjust() [2/2]

QRectF KoSvgText::ResolutionHandler::adjust ( const QRectF rect) const

Adjusts the rect to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVertical are true.

Definition at line 1754 of file KoSvgText.cpp.

1754 {
1755 return QRectF(adjust(rect.topLeft()), adjust(rect.bottomRight()));
1756}
QPointF adjust(const QPointF point) const
Adjusts the point to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVer...

References adjust().

◆ adjustCeil()

QPointF KoSvgText::ResolutionHandler::adjustCeil ( const QPointF point) const

Adjusts the point to ceiled pixel values.

See also
adjust(QPointF);

Definition at line 1735 of file KoSvgText.cpp.

1736{
1737 if (!roundToPixelHorizontal && !roundToPixelVertical) return point;
1738 QPointF pix = pointToPixel().map(point);
1740 pix.setX(ceil(pix.x()));
1741 }
1743 pix.setY(ceil(pix.y()));
1744 }
1745 return pixelToPoint().map(pix);
1746}

References pixelToPoint(), pointToPixel(), roundToPixelHorizontal, and roundToPixelVertical.

◆ adjustFloor()

QPointF KoSvgText::ResolutionHandler::adjustFloor ( const QPointF point) const

Adjusts the point to floored pixel values.

See also
adjust(QPointF);

Definition at line 1722 of file KoSvgText.cpp.

1723{
1724 if (!roundToPixelHorizontal && !roundToPixelVertical) return point;
1725 QPointF pix = pointToPixel().map(point);
1727 pix.setX(floor(pix.x()));
1728 }
1730 pix.setY(floor(pix.y()));
1731 }
1732 return pixelToPoint().map(pix);
1733}

References pixelToPoint(), pointToPixel(), roundToPixelHorizontal, and roundToPixelVertical.

◆ adjustWithOffset()

QPointF KoSvgText::ResolutionHandler::adjustWithOffset ( const QPointF point,
const QPointF offset ) const

For text decoration, we need to ensure that the whole thing, including width and height is aligned to the pixel. So this adds the offset (half the total width) and uses that to round to.

Definition at line 1748 of file KoSvgText.cpp.

1749{
1750 if (!roundToPixelHorizontal && !roundToPixelVertical) return point;
1751 return adjust(point+offset)-offset;
1752}

References adjust(), roundToPixelHorizontal, and roundToPixelVertical.

◆ freeTypePixelToPointFactor()

qreal KoSvgText::ResolutionHandler::freeTypePixelToPointFactor ( const bool x = true) const

Definition at line 1693 of file KoSvgText.cpp.

1693 {
1694 return (1.0/freeTypePixel) * pixelToPointFactor(x);
1695}
qreal pixelToPointFactor(const bool x=true) const

References freeTypePixel, and pixelToPointFactor().

◆ freeTypeToPixelTransform()

QTransform KoSvgText::ResolutionHandler::freeTypeToPixelTransform ( ) const

Definition at line 1697 of file KoSvgText.cpp.

1697 {
1698 return QTransform::fromScale(1/freeTypePixel, -1/freeTypePixel);
1699}

References freeTypePixel.

◆ freeTypeToPointTransform()

QTransform KoSvgText::ResolutionHandler::freeTypeToPointTransform ( ) const

Definition at line 1701 of file KoSvgText.cpp.

1702{
1704}
QTransform freeTypeToPixelTransform() const

References freeTypeToPixelTransform(), and pixelToPoint().

◆ pixelToPoint()

QTransform KoSvgText::ResolutionHandler::pixelToPoint ( ) const

Definition at line 1706 of file KoSvgText.cpp.

1706 {
1707 return QTransform::fromScale(pointInInch / xRes, pointInInch / yRes);
1708}

References pointInInch, xRes, and yRes.

◆ pixelToPointFactor()

qreal KoSvgText::ResolutionHandler::pixelToPointFactor ( const bool x = true) const

Definition at line 1766 of file KoSvgText.cpp.

References pointInInch, xRes, and yRes.

◆ pointToPixel()

QTransform KoSvgText::ResolutionHandler::pointToPixel ( ) const

Definition at line 1762 of file KoSvgText.cpp.

1762 {
1763 return QTransform::fromScale(xRes/pointInInch, yRes/pointInInch);
1764}

References pointInInch, xRes, and yRes.

◆ pointToPixelFactor()

qreal KoSvgText::ResolutionHandler::pointToPixelFactor ( const bool x = true) const

Definition at line 1758 of file KoSvgText.cpp.

1758 {
1760}

References pointInInch, xRes, and yRes.

Member Data Documentation

◆ freeTypePixel

const qreal KoSvgText::ResolutionHandler::freeTypePixel = 64.0

Definition at line 1095 of file KoSvgText.h.

◆ pointInInch

const qreal KoSvgText::ResolutionHandler::pointInInch = 72.0

Definition at line 1096 of file KoSvgText.h.

◆ roundToPixelHorizontal

bool KoSvgText::ResolutionHandler::roundToPixelHorizontal = false

Definition at line 1092 of file KoSvgText.h.

◆ roundToPixelVertical

bool KoSvgText::ResolutionHandler::roundToPixelVertical = false

Definition at line 1093 of file KoSvgText.h.

◆ xRes

qreal KoSvgText::ResolutionHandler::xRes = 72.0

Definition at line 1090 of file KoSvgText.h.

◆ yRes

qreal KoSvgText::ResolutionHandler::yRes = 72.0

Definition at line 1091 of file KoSvgText.h.


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