Skip to content

Commit

Permalink
509: how to get exact bound of a glyph
Browse files Browse the repository at this point in the history
  • Loading branch information
prepare committed May 13, 2017
1 parent 32e690d commit 23f5cac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
39 changes: 26 additions & 13 deletions Demo/Windows/PixelFarmSample.WinForms/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@prepare

prepare May 13, 2017

Author Member

I test with 'j' to demonstrate a glyph the lower bounds is below the baseline

//---------------------------------------------------------
////3.
//GlyphTranslatorToContour tx = new GlyphTranslatorToContour();
Expand Down Expand Up @@ -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.

Copy link
@prepare

prepare May 13, 2017

Author Member

@hexland
This is an early fix.
please test it out, If this is suite for you or not?


msdf_1
pic 1: test with 'j' , to demonstrate glyph that its lower bound is below the baseline


msdf_2
pic 2: get Glyph and its exact (original) bounds


msdf_3
pic3: scale it down, to the same scale that we want (1f/64 for msdfgen)

  • from pic3, ymin < 0 that is because the lower bound of 'j' is below the baseline
  • the glyph ymax is height of the part above the baseline
  • total glyph height = ymax-ymin

//-----------------------------------
GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, msdfGenParams);
atlasBuilder.AddGlyph(gindex, glyphImg);
int w = glyphImg.Width;
Expand Down
4 changes: 1 addition & 3 deletions Typography.OpenFont/OpenFontReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ public Typeface Read(Stream stream, ReadFlags readFlags = ReadFlags.Full)

EBLCTable fontBmpTable = ReadTableIfExists(tables, input, new EBLCTable());
//---------------------------------------------
//about truetype instruction init


//about truetype instruction init

//---------------------------------------------
var typeface = new Typeface(
Expand Down

0 comments on commit 23f5cac

Please sign in to comment.