LoadGlyph has unexpected size on certain glyphs #224
-
|
I wonder if this is cause by mistakes in my code. Here is the effect I expected to get, using freetype render sdf: This one uses msdf: Two character here have obvious size difference: And here is my code generating a msdf bitmap: export
[[nodiscard]] bitmap load_glyph(
msdfgen::FontHandle* face,
msdfgen::unicode_t code,
unsigned w,
unsigned h,
unsigned l,
unsigned top,
double range = sdf_image_range
){
using namespace msdfgen;
Shape shape;
if(loadGlyph(shape, face, code, FONT_SCALING_NONE)){
bitmap bitmap = {w + sdf_image_boarder, h + sdf_image_boarder};
shape.inverseYAxis = true;
shape.orientContours();
shape.normalize();
auto bound = shape.getBounds();
double width = bound.r - bound.l;
double height = bound.t - bound.b;
auto scale = bitmap.extent().as<double>().sub(sdf_image_boarder, sdf_image_boarder).div(width, height);
using sdf_bitmap = Bitmap<float, 3>;
edgeColoringSimple(shape, 2.5);
sdf_bitmap msdf(bitmap.width(), bitmap.height());
auto offx = -bound.l + sdf_image_boarder / 2. / scale.x;
auto offy = -bound.b + sdf_image_boarder / 2. / scale.y;
SDFTransformation t(
Projection(
Vector2{
scale.x,
scale.y
}, Vector2(
offx,
offy
)), Range(range));
msdfgen::generateMSDF(msdf, shape, t);
msdfgen::simulate8bit(msdf);
msdf::write_to_bitmap(bitmap, msdf);
return bitmap;
}
return {};
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
You are literally setting a different scale for each glyph based on its visual size. Are you sure you have any idea what you're doing? Maybe try adding this symbol: "。" and you will see what the problem is. |
Beta Was this translation helpful? Give feedback.
-
I can't tell the difference about the typesettings |
Beta Was this translation helpful? Give feedback.






I don't know what you're doing exactly, but you definitely need to use the same scale.x, scale.y for all characters.