On 3/27/19 4:25 PM, Akihiro Sagawa wrote:
/* FIXME: figure out the CJK values. */
default_left_margin = width / 2;
default_right_margin = width / 2;
if (is_cjk_charset(dc)) {
/* In the CJK case, use the minimum side bearings in hhea table */
UINT ret;
DWORD ppem, em_scale = 0;
OUTLINETEXTMETRICW *otm;
short min_lsb, min_rsb;
ret = GetOutlineTextMetricsW(dc, 0, NULL);
if (!ret) goto fail;
otm = HeapAlloc(GetProcessHeap(), 0, ret);
if (!otm) goto fail;
otm->otmSize = sizeof(*otm);
if (!GetOutlineTextMetricsW(dc, ret, otm)) goto fail;
ppem = tm.tmHeight - tm.tmInternalLeading;
em_scale = MulDiv(ppem, 1 << 16, otm->otmEMSquare);
HeapFree(GetProcessHeap(), 0, otm);
if (!get_side_bearings(dc, &min_lsb, &min_rsb)) goto fail;
default_left_margin = get_cjk_fontinfo_margin(width, min_lsb, em_scale);
default_right_margin = get_cjk_fontinfo_margin(width, min_rsb, em_scale);
} else {
fail:
default_left_margin = width / 2;
default_right_margin = width / 2;
}
You don't need to allocate 'otm', it's only necessary when you need string components.
Also please avoid goto jump across branches, you can simply make get_side_bearings() a part of condition, so default case will be hit naturally.