Jump to content

TW3FontDetector ignores Weight of font resulting in wrong text measurements


Recommended Posts

Background

 

Measuring a text is very important for beautiful layouts and is essential for layout design in order to properly align texts.

 

Platform

 

Smart Mobile Studio 2.2.0.4165

Windows 10

 

Problem

 

When calling TW3MovableControl.MeasureText the wrong dimensions of a text is returned.

 

This causes a weighted font to clip with "..." if a very specific weight is not set to the font.

 

Cause of problem

 

Inside SmartCL.Fonts there is a class called TW3FontDetector which contains a method called getFontInfo that

gets the style of a font based on a handle from the document and stores this information inside the results which is of

type TW3FontInfo.

 

Bug 1

 

getFontInfo does not contain any code that retrieves and stores the weight of the style.

 

 

Bug 2

 

TW3FontInfo also contains four overloaded methods called MeasureText which do not respect the weight of the font

and do not contain any parameter for the weight.

 

 

Bug 3

 

The methods MeasureText do not contain any code to utilize the weight of the font and does not correctly format the temporary

element called "p" which will contain the text and be used to retrieve the text dimensions.

 

Bug 4

 

The two last methods of MeasureText are very similar, but one contains code for setting the style of display and white-space and the other does not.

 

Solution: Both methods should contain that code.

 

Bug 5

 

The two last methods of MeasureText return the dimension of the text, which is correct, but according to the internet the

result should be "the dimension of the text + 1".

 

Solution: So the correct code should be

result.tmWidth := mElement.scrollWidth + 1;

result.tmHeight := mElement.scrollHeight + 1;

 

 

Solution

 

I've attached a modified version of SmartCL.Fonts.

 

SmartCL.Fonts.pas.zip

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...