Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using clustering model for the text width estimation #594

Merged
merged 15 commits into from
Sep 14, 2022
Merged

Conversation

ASmirnov-HORIS
Copy link
Collaborator

No description provided.

@ASmirnov-HORIS ASmirnov-HORIS marked this pull request as draft September 13, 2022 16:53

private fun getFaceCoefficient(font: Font): Double {
return when {
font.isBold && font.isItalic -> 0.9172120995070999
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how bold-italic style can have coefficient 0.9 and just italic - only 0.18?
Why "normal" coefficient is near 0.0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an additive coefficient.
So, coeff(italic) + coeff(bold) is approximately equal to coeff(bold-italic).
And coeff(normal) should be zero, but it is just almost zero because of calculations (face coefficient calculated after the family coefficient).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think a correction by e-17 makes any difference?

private const val SIZE_COEFFICIENT = 0.9843304096547842

private fun getCharWidth(char: Char): Double {
val clusterId = CLUSTERS.indexOfFirst { char in it }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let use a hash map for the symbol lookup.
Init the hash map using elements of the CLUSTERS list.

private const val DEFAULT_FAMILY = "Lucida Grande"
private const val DEFAULT_FONT_SIZE = 14

private val CLUSTERS = listOf(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I added it, but a bit higher.

@@ -12,6 +12,7 @@ class FontFamily private constructor(private val myName: String) {
}

companion object {
val DEFAULT_FONT_FAMILY = forName("\"Lucida Grande\", sans-serif")
val MONOSPACED = forName("monospace")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, does "monospace" family work. Would be nice if it does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It work.
But this particular variable is never used.

@ASmirnov-HORIS ASmirnov-HORIS marked this pull request as ready for review September 14, 2022 14:38
@alshan alshan merged commit 8b15cd2 into master Sep 14, 2022
@ASmirnov-HORIS ASmirnov-HORIS deleted the clustering-for-twe branch September 15, 2022 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants