-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
509: how to get exact bound of a glyph
- Loading branch information
Showing
2 changed files
with
27 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -636,20 +636,20 @@ private void cmdBuildMsdfTexture_Click(object sender, EventArgs e) | |
//samples... | ||
//1. create texture from specific glyph index range | ||
string sampleFontFile = @"..\..\..\TestFonts\tahoma.ttf"; | ||
CreateSampleMsdfTextureFont( | ||
sampleFontFile, | ||
18, | ||
0, | ||
255, | ||
"d:\\WImageTest\\sample_msdf.png"); | ||
//CreateSampleMsdfTextureFont( | ||
// sampleFontFile, | ||
// 18, | ||
// 0, | ||
// 255, | ||
// "d:\\WImageTest\\sample_msdf.png"); | ||
//--------------------------------------------------------- | ||
//2. for debug, create from some unicode chars | ||
// | ||
//CreateSampleMsdfTextureFont( | ||
// sampleFontFile, | ||
// 18, | ||
// new char[] { 'I' }, | ||
// "d:\\WImageTest\\sample_msdf.png"); | ||
CreateSampleMsdfTextureFont( | ||
sampleFontFile, | ||
18, | ||
new char[] { 'j' }, | ||
"d:\\WImageTest\\sample_msdf2.png"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
//--------------------------------------------------------- | ||
////3. | ||
//GlyphTranslatorToContour tx = new GlyphTranslatorToContour(); | ||
|
@@ -693,12 +693,25 @@ static void CreateSampleMsdfTextureFont( | |
{ | ||
//build glyph | ||
ushort gindex = typeface.LookupIndex(chars[i]); | ||
builder.BuildFromGlyphIndex(gindex, -1); | ||
//----------------------------------- | ||
//get exact bounds of glyphs | ||
Glyph glyph = typeface.GetGlyphByIndex(gindex); | ||
Bounds bounds = glyph.Bounds; //exact bounds | ||
|
||
//----------------------------------- | ||
builder.BuildFromGlyphIndex(gindex, -1); | ||
var glyphToContour = new GlyphTranslatorToContour(); | ||
//glyphToContour.Read(builder.GetOutputPoints(), builder.GetOutputContours()); | ||
builder.ReadShapes(glyphToContour); | ||
msdfGenParams.shapeScale = 1f / 64; | ||
float scale = 1f / 64; | ||
msdfGenParams.shapeScale = scale; | ||
float s_xmin = bounds.XMin * scale; | ||
float s_xmax = bounds.XMax * scale; | ||
float s_ymin = bounds.YMin * scale; | ||
float s_ymax = bounds.YMax * scale; | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
prepare
Author
Member
|
||
|
||
//----------------------------------- | ||
GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, msdfGenParams); | ||
atlasBuilder.AddGlyph(gindex, glyphImg); | ||
int w = glyphImg.Width; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I test with 'j' to demonstrate a glyph the lower bounds is below the baseline