Decrease fonts memory use (#10618)

Instead of opening the same font multiple times for each different
size (multiple face instances), share one face instance and create
multiple size instances.
This commit is contained in:
Benoit Pierre
2023-07-04 07:13:16 +00:00
committed by GitHub
parent fc89b1affa
commit 346d8eb83e
7 changed files with 29 additions and 29 deletions

View File

@@ -81,7 +81,7 @@ function TextWidget:getFontSizeToFitHeight(font_name, height_px, padding)
break
end
local face = Font:getFace(font_name, font_size)
local face_height = face.ftface:getHeightAndAscender()
local face_height = face.ftsize:getHeightAndAscender()
face_height = math.ceil(face_height) + 2*padding
until face_height <= height_px
return font_size
@@ -109,7 +109,7 @@ function TextWidget:updateSize()
-- But better compute baseline alignment from freetype font metrics
-- to get better vertical centering of text in box
-- (Freetype doc on this at https://www.freetype.org/freetype2/docs/tutorial/step2.html)
local face_height, face_ascender = self.face.ftface:getHeightAndAscender()
local face_height, face_ascender = self.face.ftsize:getHeightAndAscender()
self._height = math.ceil(face_height) + 2*self.padding
self._baseline_h = Math.round(face_ascender) + self.padding
-- With our UI fonts, this usually gives 0.72 to 0.74, so text is aligned