Supported mimicry fonts: - Greek - TekniaGreek
Type: | mimicryTypefaceConverter |
Uses (at least one of): | |
Requires (at least one of): |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2013, Marten de Vries
#
# This file is part of OpenTeacher.
#
# OpenTeacher is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenTeacher is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
class MimicryTypefaceConverterModule:
"""Supported mimicry fonts:
- Greek
- TekniaGreek
"""
def __init__(self, moduleManager, *args, **kwargs):
super().__init__(*args, **kwargs)
self._mm = moduleManager
self.type = "mimicryTypefaceConverter"
def convert(self, font, text):
"""If 'font' is a known mimicry font, all letters in 'text' are
converted into their unicode equivalent. Unknown letters just
remain the same.
"""
fontTable = {
#Symbol font (Greek chars)
"symbol": {
#Source: http://en.wikipedia.org/wiki/Symbol_%28typeface%29#Font_comparison
#lowercase
u"a": u"α",
u"b": u"β",
u"g": u"γ",
u"d": u"δ",
u"e": u"ε",
u"z": u"ζ",
u"h": u"η",
u"q": u"θ",
u"i": u"ι",
u"k": u"κ",
u"l": u"λ",
u"m": u"μ",
u"n": u"ν",
u"x": u"ξ",
u"o": u"ο",
u"p": u"π",
u"r": u"ρ",
u"V": u"ς",
u"s": u"σ",
"t": u"τ",
u"u": u"υ",
u"f": u"φ",
u"c": u"χ",
u"y": u"ψ",
u"w": u"ω",
#uppercase
u"A": u"Α",
u"B": u"Β",
u"G": u"Γ",
u"D": u"Δ",
u"E": u"Ε",
u"Z": u"Ζ",
u"H": u"Η",
u"Q": u"Θ",
u"I": u"Ι",
u"K": u"Κ",
u"L": u"Λ",
u"M": u"Μ",
u"N": u"Ν",
u"X": u"Ξ",
u"O": u"Ο",
u"P": u"Π",
u"R": u"Ρ",
u"S": u"Σ",
u"T": u"Τ",
u"U": u"Υ",
u"F": u"Φ",
u"C": u"Χ",
u"Y": u"Ψ",
u"W": u"Ω",
},
}
#Greek font (as supplied by Teach2000)
fontTable["greek"] = fontTable["symbol"]
fontTable["greek"].update({
u"j": u"ς",
u"v": u"ᾳ",
u"J": u"ῷ",
u"V": u"ῃ",
})
#TekniaGreek. This might not be accurate, but better than
#nothing...
fontTable["tekniagreek"] = fontTable["greek"]
font = font.lower()
letterTable = fontTable.get(font, {})
return "".join((letterTable.get(letter, letter) for letter in text))
def enable(self):
self.active = True
def disable(self):
self.active = False
def init(moduleManager):
return MimicryTypefaceConverterModule(moduleManager)
|