MCPcopy Create free account
hub / github.com/SpartanJ/eepp / getAbsoluteFontSize

Method getAbsoluteFontSize

src/eepp/ui/uinode.cpp:1767–1801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1765}
1766
1767Float UINode::getAbsoluteFontSize( const UIWidget* widget ) const {
1768 std::string pxStr = widget->getPropertyString(
1769 StyleSheetSpecification::instance()->getProperty( PropertyId::FontSize ) );
1770 if ( pxStr.empty() )
1771 return 12.f * PixelDensity::getPixelDensity();
1772 StyleSheetLength len( pxStr );
1773 if ( len.getUnit() == StyleSheetLength::Unit::Rem ) {
1774 Float rootFontSize = 12.f * PixelDensity::getPixelDensity();
1775 if ( widget->getUISceneNode() ) {
1776 UIWidget* docRoot = const_cast<UIWidget*>( widget );
1777 while ( docRoot->getParent() && docRoot->getParent()->isWidget() ) {
1778 if ( docRoot->getElementTag() == "html" )
1779 break;
1780 docRoot = docRoot->getParent()->asType<UIWidget>();
1781 }
1782 rootFontSize = getAbsoluteFontSize( docRoot );
1783 }
1784 return len.getValue() * rootFontSize;
1785 } else if ( len.getUnit() == StyleSheetLength::Unit::Em ||
1786 len.getUnit() == StyleSheetLength::Unit::Percentage ) {
1787 Float parentFontSize = 12.f;
1788 Node* pNode = widget->getParent();
1789 while ( pNode ) {
1790 if ( pNode->isWidget() ) {
1791 parentFontSize = getAbsoluteFontSize( pNode->asType<UIWidget>() );
1792 break;
1793 }
1794 pNode = pNode->getParent();
1795 }
1796 if ( len.getUnit() == StyleSheetLength::Unit::Em )
1797 return len.getValue() * parentFontSize;
1798 return ( len.getValue() / 100.f ) * parentFontSize;
1799 }
1800 return widget->convertLength( len, 0 );
1801}
1802
1803}} // namespace EE::UI

Callers

nothing calls this directly

Calls 9

isWidgetMethod · 0.80
convertLengthMethod · 0.80
getPropertyStringMethod · 0.45
getPropertyMethod · 0.45
emptyMethod · 0.45
getUnitMethod · 0.45
getUISceneNodeMethod · 0.45
getParentMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected