defget_mygsig(full_url, timestamp, page_load_ts): parsed = urlparse(full_url) qp = parse_qs(parsed.query, keep_blank_values=True) merged = {k: v[0] for k, v in qp.items()} merged['path'] = parsed.path # 把 path 也塞进去
# 按 key 字母顺序排(不区分大小写),取 value 用 "_" 连起来 sorted_entries = sorted(merged.items(), key=lambda x: x[0].lower()) joined = "_".join(str(v) for _, v in sorted_entries)
# "581409236#" + joined + "$" + ts -> md5 full = f"581409236#{joined}${timestamp}" ms1 = hashlib.md5(full.encode()).hexdigest()
info = [] for code, name in cmap.items(): if code <= 0xFF: # 只看自定义区 continue g = glyf[name] if g.numberOfContours <= 0: continue coords = list(g.coordinates) xs = [c[0] for c in coords] ys = [c[1] for c in coords] info.append({ 'unicode': code, 'name': name, 'contours': g.numberOfContours, 'points': len(coords), 'width': max(xs) - min(xs), 'height': max(ys) - min(ys), 'endPts': list(g.endPtsOfContours), }) return info, glyf, cmap
defidentify(glyphs, glyf, cmap): mapping = {} one = [g for g in glyphs if g['contours'] == 1] two = [g for g in glyphs if g['contours'] == 2] three = [g for g in glyphs if g['contours'] >= 3]
# 8: 三轮廓 for g in three: mapping[g['unicode']] = 8
# 1: 一轮廓里最窄 one.sort(key=lambda x: x['width']) mapping[one[0]['unicode']] = 1 # 7: 剩下里点数最少 rest = one[1:] rest.sort(key=lambda x: x['points']) mapping[rest[0]['unicode']] = 7 # 2/3/5: 上下 x 重心偏移 others = rest[1:] for g in others: cs = list(glyf[cmap[g['unicode']]].coordinates) mid = (min(c[1] for c in cs) + max(c[1] for c in cs)) / 2 up = [c[0] for c in cs if c[1] > mid] lo = [c[0] for c in cs if c[1] <= mid] g['shift'] = (sum(up)/len(up) if up else0) - (sum(lo)/len(lo) if lo else0) others.sort(key=lambda x: x['shift'], reverse=True) mapping[others[0]['unicode']] = 2# 上重心偏右 mapping[others[1]['unicode']] = 3# 居中 mapping[others[2]['unicode']] = 5# 上重心偏左
# 2轮廓: 4, 0, 6, 9 two.sort(key=lambda x: x['points']) mapping[two[0]['unicode']] = 4# 点数最少 = 三角形内轮廓 rest2 = two[1:] for g in rest2: cs = list(glyf[cmap[g['unicode']]].coordinates) end = list(glyf[cmap[g['unicode']]].endPtsOfContours) c1 = cs[:end[0]+1] c2 = cs[end[0]+1:end[1]+1] iflen(end) > 1else [] inner = c1 iflen(c1) < len(c2) else c2 if inner: mid = (min(c[1] for c in cs) + max(c[1] for c in cs)) / 2 g['inner_rel'] = sum(c[1] for c in inner)/len(inner) - mid rest2.sort(key=lambda x: abs(x.get('inner_rel', 0))) mapping[rest2[0]['unicode']] = 0# 最居中 tail = sorted(rest2[1:], key=lambda x: x.get('inner_rel', 0)) mapping[tail[0]['unicode']] = 6# 偏下 mapping[tail[1]['unicode']] = 9# 偏上 return mapping