MCPcopy Create free account
hub / github.com/SFML/SFML / setCurrentSize

Method setCurrentSize

src/SFML/Graphics/Font.cpp:766–803  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

764
765////////////////////////////////////////////////////////////
766bool Font::setCurrentSize(unsigned int characterSize) const
767{
768 // FT_Set_Pixel_Sizes is an expensive function, so we must call it
769 // only when necessary to avoid killing performances
770
771 // m_fontHandles and m_fontHandles->face are checked to be non-null before calling this method
772 FT_Face face = m_fontHandles->face;
773 const FT_UShort currentSize = face->size->metrics.x_ppem;
774
775 if (currentSize != characterSize)
776 {
777 const FT_Error result = FT_Set_Pixel_Sizes(face, 0, characterSize);
778
779 if (result == FT_Err_Invalid_Pixel_Size)
780 {
781 // In the case of bitmap fonts, resizing can
782 // fail if the requested size is not available
783 if (!FT_IS_SCALABLE(face))
784 {
785 err() << "Failed to set bitmap font size to " << characterSize << '\n' << "Available sizes are: ";
786 for (int i = 0; i < face->num_fixed_sizes; ++i)
787 {
788 const long size = (face->available_sizes[i].y_ppem + 32) >> 6;
789 err() << size << " ";
790 }
791 err() << std::endl;
792 }
793 else
794 {
795 err() << "Failed to set font size to " << characterSize << std::endl;
796 }
797 }
798
799 return result == FT_Err_Ok;
800 }
801
802 return true;
803}
804
805
806////////////////////////////////////////////////////////////

Callers 1

ensureGeometryUpdateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected