From 3dd93782c1e96d2a1970f1ded4c8f32c2f001428 Mon Sep 17 00:00:00 2001 From: be5invis Date: Sun, 15 Jan 2017 23:23:39 +0800 Subject: [PATCH] optimize shape of arc box-drawing glyphs (U+256D-U+2570) --- glyphs/symbol-geometric.ptl | 377 +++++++++++++++++++----------------- 1 file changed, 194 insertions(+), 183 deletions(-) diff --git a/glyphs/symbol-geometric.ptl b/glyphs/symbol-geometric.ptl index 732f720..fcbf92c 100644 --- a/glyphs/symbol-geometric.ptl +++ b/glyphs/symbol-geometric.ptl @@ -451,208 +451,219 @@ export : define [apply] : begin save 'rightHalfBlock' 0x2590 ### Box drawing glyphs - ### 'Box-Drawing' - local light : adviceBlackness 3.5 - local heavy : Math.max (light * 2) (WIDTH * 0.15) - local width FULLWIDTH - local midx : FULLWIDTH / 2 - local midy : mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent 0.5 + do "Box Drawing" + local light : adviceBlackness 3.5 + local heavy : Math.max (light * 2) (WIDTH * 0.15) + local width FULLWIDTH + local midx : FULLWIDTH / 2 + local topy font.OS_2.usWinAscent + local boty (-font.OS_2.usWinDescent) + local midy : mix boty topy 0.5 - define [boxdraw unicode u d l r] : sketch - set-width width - local stopH : [Math.max u d] / 2 - local stopV : [Math.max l r] / 2 - if l : include : HBar 0 (midx + stopH) midy l - if r : include : HBar (midx - stopH) width midy r - if d : include : VBar midx (-font.OS_2.usWinDescent) (midy + stopV) d - if u : include : VBar midx (midy - stopV) font.OS_2.usWinAscent u + define [boxdraw unicode u d l r] : sketch + set-width width + local stopH : [Math.max u d] / 2 + local stopV : [Math.max l r] / 2 + if l : include : HBar 0 (midx + stopH) midy l + if r : include : HBar (midx - stopH) width midy r + if d : include : VBar midx (-font.OS_2.usWinDescent) (midy + stopV) d + if u : include : VBar midx (midy - stopV) font.OS_2.usWinAscent u - save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode + save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode - define [dlboxdraw unicode u d l r] : sketch - set-width width - local stopH : [Math.max u d] - light * 1 - light * 0.5 * HVCONTRAST - local stopV : [Math.max l r] - light * 1.5 - local capH : [Math.max u d] - light * 1 - local capV : [Math.max l r] - light * 1 - if l : begin - include : HBar 0 (midx - stopH) (midy + (l - light)) light - if (l > light) : include : HBar 0 (midx - stopH) (midy - (l - light)) light - if r : begin - include : HBar (midx + stopH) width (midy + (r - light)) light - if (r > light) : include : HBar (midx + stopH) width (midy - (r - light)) light - if d : begin - include : VBar (midx + (d - light)) (-font.OS_2.usWinDescent) (midy - stopV) light - if (d > light) : include : VBar (midx - (d - light)) (-font.OS_2.usWinDescent) (midy - stopV) light - if u : begin - include : VBar (midx + (u - light)) (midy + stopV) font.OS_2.usWinAscent light - if (u > light) : include : VBar (midx - (u - light)) (midy + stopV) font.OS_2.usWinAscent light - if (stopH > 0 && [not u]) : include : HBar (midx - stopH - light * HVCONTRAST) (midx + stopH + light * HVCONTRAST) (midy + capV) light - if (stopH > 0 && [not d]) : include : HBar (midx - stopH - light * HVCONTRAST) (midx + stopH + light * HVCONTRAST) (midy - capV) light - if (stopV > 0 && [not l]) : include : VBar (midx - capH) (midy - stopV - light) (midy + stopV + light) light - if (stopV > 0 && [not r]) : include : VBar (midx + capH) (midy - stopV - light) (midy + stopV + light) light + define [dlboxdraw unicode u d l r] : sketch + set-width width + local stopH : [Math.max u d] - light * 1 - light * 0.5 * HVCONTRAST + local stopV : [Math.max l r] - light * 1.5 + local capH : [Math.max u d] - light * 1 + local capV : [Math.max l r] - light * 1 + if l : begin + include : HBar 0 (midx - stopH) (midy + (l - light)) light + if (l > light) : include : HBar 0 (midx - stopH) (midy - (l - light)) light + if r : begin + include : HBar (midx + stopH) width (midy + (r - light)) light + if (r > light) : include : HBar (midx + stopH) width (midy - (r - light)) light + if d : begin + include : VBar (midx + (d - light)) (-font.OS_2.usWinDescent) (midy - stopV) light + if (d > light) : include : VBar (midx - (d - light)) (-font.OS_2.usWinDescent) (midy - stopV) light + if u : begin + include : VBar (midx + (u - light)) (midy + stopV) font.OS_2.usWinAscent light + if (u > light) : include : VBar (midx - (u - light)) (midy + stopV) font.OS_2.usWinAscent light + if (stopH > 0 && [not u]) : include : HBar (midx - stopH - light * HVCONTRAST) (midx + stopH + light * HVCONTRAST) (midy + capV) light + if (stopH > 0 && [not d]) : include : HBar (midx - stopH - light * HVCONTRAST) (midx + stopH + light * HVCONTRAST) (midy - capV) light + if (stopV > 0 && [not l]) : include : VBar (midx - capH) (midy - stopV - light) (midy + stopV + light) light + if (stopV > 0 && [not r]) : include : VBar (midx + capH) (midy - stopV - light) (midy + stopV + light) light - save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode + save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode - define [complexBoxDraw unicodeStart U D L R fn dl] : begin - local order { - {light light light light} - {light light heavy light} - {light light light heavy} - {light light heavy heavy} - {heavy light light light} - {light heavy light light} - {heavy heavy light light} - {heavy light heavy light} - {heavy light light heavy} - {light heavy heavy light} - {light heavy light heavy} - {heavy light heavy heavy} - {light heavy heavy heavy} - {heavy heavy heavy light} - {heavy heavy light heavy} - {heavy heavy heavy heavy} - } - local existings {} - local n 0 - foreach {u d l r} [items-of order] : begin - local newcome true - local masked {(U * u) (D * d) (L * l) (R * r)} - foreach existing [items-of existings] : if ('' + existing === '' + masked) : set newcome false - if newcome : begin - if ([not dl] - || ([not masked.0] || [not masked.1] || (masked.0 === masked.1)) - && ([not masked.2] || [not masked.3] || (masked.2 === masked.3)) - && (masked.0 > light || masked.1 > light || masked.2 > light || masked.3 > light) - ) : begin - [fallback fn boxdraw].apply null {(unicodeStart + n) :: masked} - inc n - existings.push masked + define [complexBoxDraw unicodeStart U D L R fn dl] : begin + local order { + {light light light light} + {light light heavy light} + {light light light heavy} + {light light heavy heavy} + {heavy light light light} + {light heavy light light} + {heavy heavy light light} + {heavy light heavy light} + {heavy light light heavy} + {light heavy heavy light} + {light heavy light heavy} + {heavy light heavy heavy} + {light heavy heavy heavy} + {heavy heavy heavy light} + {heavy heavy light heavy} + {heavy heavy heavy heavy} + } + local existings {} + local n 0 + foreach {u d l r} [items-of order] : begin + local newcome true + local masked {(U * u) (D * d) (L * l) (R * r)} + foreach existing [items-of existings] : if ('' + existing === '' + masked) : set newcome false + if newcome : begin + if ([not dl] + || ([not masked.0] || [not masked.1] || (masked.0 === masked.1)) + && ([not masked.2] || [not masked.3] || (masked.2 === masked.3)) + && (masked.0 > light || masked.1 > light || masked.2 > light || masked.3 > light) + ) : begin + [fallback fn boxdraw].apply null {(unicodeStart + n) :: masked} + inc n + existings.push masked - # Straight - boxdraw 0x2500 0 0 light light - boxdraw 0x2501 0 0 heavy heavy - boxdraw 0x2502 light light 0 0 - boxdraw 0x2503 heavy heavy 0 0 - boxdraw 0x2574 0 0 light 0 - boxdraw 0x2575 light 0 0 0 - boxdraw 0x2576 0 0 0 light - boxdraw 0x2577 0 light 0 0 - boxdraw 0x2578 0 0 heavy 0 - boxdraw 0x2579 heavy 0 0 0 - boxdraw 0x257A 0 0 0 heavy - boxdraw 0x257B 0 heavy 0 0 - boxdraw 0x257C 0 0 light heavy - boxdraw 0x257D light heavy 0 0 - boxdraw 0x257E 0 0 heavy light - boxdraw 0x257F heavy light 0 0 - dlboxdraw 0x2550 0 0 heavy heavy - dlboxdraw 0x2551 heavy heavy 0 0 + # Straight + boxdraw 0x2500 0 0 light light + boxdraw 0x2501 0 0 heavy heavy + boxdraw 0x2502 light light 0 0 + boxdraw 0x2503 heavy heavy 0 0 + boxdraw 0x2574 0 0 light 0 + boxdraw 0x2575 light 0 0 0 + boxdraw 0x2576 0 0 0 light + boxdraw 0x2577 0 light 0 0 + boxdraw 0x2578 0 0 heavy 0 + boxdraw 0x2579 heavy 0 0 0 + boxdraw 0x257A 0 0 0 heavy + boxdraw 0x257B 0 heavy 0 0 + boxdraw 0x257C 0 0 light heavy + boxdraw 0x257D light heavy 0 0 + boxdraw 0x257E 0 0 heavy light + boxdraw 0x257F heavy light 0 0 + dlboxdraw 0x2550 0 0 heavy heavy + dlboxdraw 0x2551 heavy heavy 0 0 - # Complex - complexBoxDraw 0x250C 0 1 0 1 - complexBoxDraw 0x2510 0 1 1 0 - complexBoxDraw 0x2514 1 0 0 1 - complexBoxDraw 0x2518 1 0 1 0 - complexBoxDraw 0x251C 1 1 0 1 - complexBoxDraw 0x2524 1 1 1 0 - complexBoxDraw 0x252C 0 1 1 1 - complexBoxDraw 0x2534 1 0 1 1 - complexBoxDraw 0x253C 1 1 1 1 - complexBoxDraw 0x2552 0 1 0 1 dlboxdraw 1 - complexBoxDraw 0x2555 0 1 1 0 dlboxdraw 1 - complexBoxDraw 0x2558 1 0 0 1 dlboxdraw 1 - complexBoxDraw 0x255B 1 0 1 0 dlboxdraw 1 - complexBoxDraw 0x255E 1 1 0 1 dlboxdraw 1 - complexBoxDraw 0x2561 1 1 1 0 dlboxdraw 1 - complexBoxDraw 0x2564 0 1 1 1 dlboxdraw 1 - complexBoxDraw 0x2567 1 0 1 1 dlboxdraw 1 - complexBoxDraw 0x256A 1 1 1 1 dlboxdraw 1 + # Complex + complexBoxDraw 0x250C 0 1 0 1 + complexBoxDraw 0x2510 0 1 1 0 + complexBoxDraw 0x2514 1 0 0 1 + complexBoxDraw 0x2518 1 0 1 0 + complexBoxDraw 0x251C 1 1 0 1 + complexBoxDraw 0x2524 1 1 1 0 + complexBoxDraw 0x252C 0 1 1 1 + complexBoxDraw 0x2534 1 0 1 1 + complexBoxDraw 0x253C 1 1 1 1 + complexBoxDraw 0x2552 0 1 0 1 dlboxdraw 1 + complexBoxDraw 0x2555 0 1 1 0 dlboxdraw 1 + complexBoxDraw 0x2558 1 0 0 1 dlboxdraw 1 + complexBoxDraw 0x255B 1 0 1 0 dlboxdraw 1 + complexBoxDraw 0x255E 1 1 0 1 dlboxdraw 1 + complexBoxDraw 0x2561 1 1 1 0 dlboxdraw 1 + complexBoxDraw 0x2564 0 1 1 1 dlboxdraw 1 + complexBoxDraw 0x2567 1 0 1 1 dlboxdraw 1 + complexBoxDraw 0x256A 1 1 1 1 dlboxdraw 1 - # Dashed - define [hDashed unicode segments weight] : sketch - set-width width - foreach j [range 0 segments] : include : HBar [mix (width * j / segments) (width * (j + 1) / segments) 0.2] [mix (width * j / segments) (width * (j + 1) / segments) 0.8] midy weight + # Dashed + define [hDashed unicode segments weight] : sketch + set-width width + foreach j [range 0 segments] : include : HBar [mix (width * j / segments) (width * (j + 1) / segments) 0.2] [mix (width * j / segments) (width * (j + 1) / segments) 0.8] midy weight - save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode + save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode - define [vDashed unicode segments weight] : sketch - set-width width - foreach j [range 0 segments] : include : VBar midx [mix [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent (j / segments)] [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent ((j + 1) / segments)] 0.2] [mix [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent (j / segments)] [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent ((j + 1) / segments)] 0.8] weight + define [vDashed unicode segments weight] : sketch + set-width width + foreach j [range 0 segments] : include : VBar midx [mix [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent (j / segments)] [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent ((j + 1) / segments)] 0.2] [mix [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent (j / segments)] [mix (-font.OS_2.usWinDescent) font.OS_2.usWinAscent ((j + 1) / segments)] 0.8] weight - save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode + save ('bd' + [unicode.toString 16 :.toUpperCase]) unicode - hDashed 0x2504 3 light - hDashed 0x2505 3 heavy - hDashed 0x2508 4 light - hDashed 0x2509 4 heavy - hDashed 0x254C 2 light - hDashed 0x254D 2 heavy - vDashed 0x2506 3 light - vDashed 0x2507 3 heavy - vDashed 0x250A 4 light - vDashed 0x250B 4 heavy - vDashed 0x254E 2 light - vDashed 0x254F 2 heavy + hDashed 0x2504 3 light + hDashed 0x2505 3 heavy + hDashed 0x2508 4 light + hDashed 0x2509 4 heavy + hDashed 0x254C 2 light + hDashed 0x254D 2 heavy + vDashed 0x2506 3 light + vDashed 0x2507 3 heavy + vDashed 0x250A 4 light + vDashed 0x250B 4 heavy + vDashed 0x254E 2 light + vDashed 0x254F 2 heavy - # Arcs - sketch # bd256D - set-width width - include : dispiro - widths.center light - g4.up.start midx (-font.OS_2.usWinDescent) [heading UPWARD] - arcvh - g4.right.end width midy [heading RIGHTWARD] - save 'bd256D' 0x256D + # Arcs + local bdArcRadius : Math.min (midx + O * 2) ((midy - boty) / 2) + sketch # bd256D + set-width width + include : dispiro + widths.center light + flat midx boty [heading UPWARD] + curl midx (midy - bdArcRadius) [heading UPWARD] + arcvh + flat (midx + bdArcRadius) midy [heading RIGHTWARD] + curl width midy [heading RIGHTWARD] + save 'bd256D' 0x256D - sketch # bd256E - set-width width - include : dispiro - widths.center light - g4.up.start midx (-font.OS_2.usWinDescent) [heading UPWARD] - arcvh - g4.left.end 0 midy [heading LEFTWARD] - save 'bd256E' 0x256E + sketch # bd256E + set-width width + include : dispiro + widths.center light + flat midx boty [heading UPWARD] + curl midx (midy - bdArcRadius) [heading UPWARD] + arcvh + flat (midx - bdArcRadius) midy [heading LEFTWARD] + curl 0 midy [heading LEFTWARD] + save 'bd256E' 0x256E - sketch # bd256F - set-width width - include : dispiro - widths.center light - g4.down.start midx font.OS_2.usWinAscent [heading DOWNWARD] - arcvh - g4.left.end 0 midy [heading LEFTWARD] - save 'bd256F' 0x256F + sketch # bd256F + set-width width + include : dispiro + widths.center light + flat midx topy [heading DOWNWARD] + curl midx (midy + bdArcRadius) [heading DOWNWARD] + arcvh + flat (midx - bdArcRadius) midy [heading LEFTWARD] + curl 0 midy [heading LEFTWARD] + save 'bd256F' 0x256F - sketch # bd2570 - set-width width - include : dispiro - widths.center light - g4.down.start midx font.OS_2.usWinAscent [heading DOWNWARD] - arcvh - g4.right.end width midy [heading RIGHTWARD] - save 'bd2570' 0x2570 + sketch # bd2570 + set-width width + include : dispiro + widths.center light + flat midx topy [heading DOWNWARD] + curl midx (midy + bdArcRadius) [heading DOWNWARD] + arcvh + flat (midx + bdArcRadius) midy [heading RIGHTWARD] + curl width midy [heading RIGHTWARD] + save 'bd2570' 0x2570 - sketch # bd2571 - set-width width - include : dispiro - widths.center light - flat width font.OS_2.usWinAscent - curl 0 (-font.OS_2.usWinDescent) - save 'bd2571' 0x2571 + sketch # bd2571 + set-width width + include : dispiro + widths.center light + flat width font.OS_2.usWinAscent + curl 0 (-font.OS_2.usWinDescent) + save 'bd2571' 0x2571 - sketch # bd2572 - set-width width - include : dispiro - widths.center light - flat 0 font.OS_2.usWinAscent - curl width (-font.OS_2.usWinDescent) - save 'bd2572' 0x2572 + sketch # bd2572 + set-width width + include : dispiro + widths.center light + flat 0 font.OS_2.usWinAscent + curl width (-font.OS_2.usWinDescent) + save 'bd2572' 0x2572 - sketch # bd2573 - set-width width - include glyphs.bd2571 - include glyphs.bd2572 - save 'bd2573' 0x2573 + sketch # bd2573 + set-width width + include glyphs.bd2571 + include glyphs.bd2572 + save 'bd2573' 0x2573 ### POWERLINE glyphs ### 'Powerline'