stbtt_GetCodepointBox and stbtt_GetFontVMetrics inconsistent values

Started by PDPIG, September 03, 2019, 18:16:40

Previous topic - Next topic

PDPIG

Hi, im trying to display a font with a pixel height of 150 but if i multiply the quad values from calling stbtt_GetBakedQuad with the scale factor from stbtt_ScaleForPixelHeight the result is ridiculously large.

So I tried to calculate the scalefactor myself by using the tallest character height and the window height, however the height from calling stbtt_GetCodepointBox varies hugely with the difference in y0 and y1 for "1" being 709 and "2" being 441 even though they are similar in height. it is the same for stbtt_GetFontVMetrics as the difference in ascent and descent being 2288 while the value for a "(" which is one of the taller characters only being 883.

Can anyone explain why there is such a large difference in the heights for the characters?

here is the code im using and the font is Arial

loadedFontData = IOUtil.ioResourceToByteBuffer(source,512 * 1024);
            stbtt_InitFont(fontinfo,loadedFontData);
            stbtt_BakeFontBitmap(loadedFontData,fontHeight,bitmap,BITMAP_WIDTH,BITMAP_HEIGHT,32,charData);

            for(int i = 32; i < 126;i++)
            {
                IntBuffer x0 = BufferUtils.createIntBuffer(1);
                IntBuffer x1 = BufferUtils.createIntBuffer(1);
                IntBuffer y0 = BufferUtils.createIntBuffer(1);
                IntBuffer y1 = BufferUtils.createIntBuffer(1);
                stbtt_GetCodepointBox(fontinfo,i,x0,x1,y0,y1);

                int test1 = y0.get(0);
                int test2 = y1.get(0);

                int difference = test2 - test1;

            }

spasi

Looks like you got the parameter order wrong. The correct is: x0, y0, x1, y1.