Last active
December 17, 2021 18:14
-
-
Save okay-type/17d0ac3ccbc6123d767dd46dd2f2cdc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# menuTitle : MM Flip Pair Mirror | |
# shortCut : control+6 | |
openclosepairs = { | |
# initial/final punctuation (from https://www.compart.com/en/unicode/category/Pi and https://www.compart.com/en/unicode/category/Pf) | |
# "‚": "‘", | |
# "„": "“", | |
# "„": "”", | |
"‘": "’", | |
# "‛": "’", | |
"“": "”", | |
# "‟": "”", | |
# "‹": "›", | |
# "›": "‹", | |
"«": "»", | |
"»": "«", | |
# "⸂": "⸃", | |
"⸄": "⸅", | |
"⸉": "⸊", | |
# "⸌": "⸍", | |
# "⸜": "⸝", | |
"⸠": "⸡", | |
"”": "”", | |
"’": "’", | |
# Miscellaneous but common open/close pairs | |
"'": "'", | |
'"': '"', | |
# "¡": "!", | |
# "¿": "?", | |
"←": "→", | |
"→": "←", | |
# opening/closing punctuation (from https://www.compart.com/en/unicode/category/Ps & https://www.compart.com/en/unicode/category/Pe) | |
"(": ")", | |
"[": "]", | |
"{": "}", | |
"parenleft.sups": "parenright.sups", | |
"parenleft.subs": "parenright.subs", | |
"parenleft.uc": "parenright.uc", | |
"bracketleft.uc": "bracketright.uc", | |
"braceleft.uc": "braceright.uc", | |
"bracketangleleft.uc": "bracketangleright.uc", | |
"guillemetleft": "guillemetright", | |
"guillemetleft.uc": "guillemetright.uc", | |
"commaheavydoubleturnedornament": "commaheavydoubleornament", | |
"parenleft.vert": "parenright.vert", | |
"bracketleft.vert": "bracketright.vert", | |
"braceleft.vert": "braceright.vert", | |
"bracketangleleft.vert": "bracketangleright.vert", | |
"guillemetleft.vert": "guillemetright.vert", | |
"parenleft.uc.vert": "parenright.uc.vert", | |
"bracketleft.uc.vert": "bracketright.uc.vert", | |
"braceleft.uc.vert": "braceright.uc.vert", | |
"bracketangleleft.uc.vert": "bracketangleright.uc.vert", | |
"guillemetleft.uc.vert": "guillemetright.uc.vert", | |
"less.vert": "greater.vert", | |
"less.vert.uc": "greater.vert.uc", | |
"<": ">", | |
">": "<", | |
"less": "greater", | |
"less.uc": "greater.uc", | |
"༺": "༻", | |
"༼": "༽", | |
"᚛": "᚜", | |
# "‚": "‘", | |
# "„": "“", | |
"⁅": "⁆", | |
"⁽": "⁾", | |
"₍": "₎", | |
"⌈": "⌉", | |
"⌊": "⌋", | |
"〈": "〉", | |
"❨": "❩", | |
"❪": "❫", | |
"❬": "❭", | |
"❮": "❯", | |
"❰": "❱", | |
"❲": "❳", | |
"❴": "❵", | |
"⟅": "⟆", | |
"⟦": "⟧", | |
"⟨": "⟩", | |
"⟪": "⟫", | |
"⟬": "⟭", | |
"⟮": "⟯", | |
"⦃": "⦄", | |
"⦅": "⦆", | |
"⦇": "⦈", | |
"⦉": "⦊", | |
"⦋": "⦌", | |
"⦍": "⦎", | |
"⦏": "⦐", | |
"⦑": "⦒", | |
"⦓": "⦔", | |
"⦕": "⦖", | |
"⦗": "⦘", | |
"⧘": "⧙", | |
"⧚": "⧛", | |
"⧼": "⧽", | |
"⸢": "⸣", | |
"⸤": "⸥", | |
"⸦": "⸧", | |
"⸨": "⸩", | |
"〈": "〉", | |
"《": "》", | |
"「": "」", | |
"『": "』", | |
"【": "】", | |
"〔": "〕", | |
"〖": "〗", | |
"〘": "〙", | |
"〚": "〛", | |
"〝": "〞", | |
"⹂": "〟", | |
"﴿": "﴾", | |
"︗": "︘", | |
"︵": "︶", | |
"︷": "︸", | |
"︹": "︺", | |
"︻": "︼", | |
"︽": "︾", | |
"︿": "﹀", | |
"﹁": "﹂", | |
"﹃": "﹄", | |
"﹇": "﹈", | |
"﹙": "﹚", | |
"﹛": "﹜", | |
"﹝": "﹞", | |
"(": ")", | |
"[": "]", | |
"{": "}", | |
"⦅": "⦆", | |
"「": "」", | |
} | |
import metricsMachine as mm | |
from glyphNameFormatter import GlyphName | |
def asGlyphName(character): | |
if len(character) > 1: | |
return character | |
else: | |
return GlyphName(ord(character)).getName() | |
f = CurrentFont() | |
pairCurrent = mm.GetCurrentPair(font=f) | |
left = asGlyphName(pairCurrent[0]) | |
right = asGlyphName(pairCurrent[1]) | |
flippedPair = [right, left] | |
for openclosepair in openclosepairs.items(): | |
if flippedPair[0] == asGlyphName(openclosepair[0]): | |
flippedPair[0] = asGlyphName(openclosepair[1]) | |
elif flippedPair[0] == asGlyphName(openclosepair[1]): | |
flippedPair[0] = asGlyphName(openclosepair[0]) | |
if flippedPair[1] == asGlyphName(openclosepair[0]): | |
flippedPair[1] = asGlyphName(openclosepair[1]) | |
elif flippedPair[1] == asGlyphName(openclosepair[1]): | |
flippedPair[1] = asGlyphName(openclosepair[0]) | |
mm.SetCurrentPair(flippedPair, font=f) | |
# print('MM Flip Pair Mirror', pairCurrent, '-->', flippedPair) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment