-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 11faaf9
Showing
6 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[bumpversion] | ||
current_version = 0.0.1 | ||
|
||
[bumpversion:file:text_braille_l18n.py] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
|
||
[*.{py,cfg,inx}] | ||
indent_size = 4 | ||
|
||
[*.{py,md}] | ||
trim_trailing_whitespace = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2021, Álvaro Mondéjar Rubio | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Braille l18n Inkscape extension | ||
|
||
This extension adds localized capabilities to Inkscape's built-in | ||
text-to-Braille converter. | ||
|
||
## Supported alphabets | ||
|
||
| Locale | Description | | ||
| ------ | ----------- | | ||
| English | [North American Braille ASCII code][en-wiki] | | ||
| Spanish | [Braille español (Grado 1)][es-wiki] | | ||
|
||
## Installation | ||
|
||
1. Download this repository. | ||
1. Move `text_braille_l18n.inx` and `text_braille_l18n.py` files to your user's | ||
extensions directory. If you don't know its location, open it from `Edit` -> | ||
`Preferences` -> `System` -> `Users extensions`. | ||
1. Run Inkscape and you'll see the extension in `Extensions` -> `Text`. | ||
|
||
## How to use | ||
|
||
Select a text that you want to convert in Braille, open this extension, | ||
chosse a locale and apply. | ||
|
||
## TODO | ||
|
||
- [ ] Spanish Braille conversion for texts not prepared for Braille | ||
translation. Add prefixes before numbers and before uppercased letters. | ||
|
||
[en-wiki]: https://en.wikipedia.org/wiki/Braille_ASCII | ||
[es-wiki]: https://es.wikipedia.org/wiki/Braille_espa%C3%B1ol |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<inkscape-extension xmlns="https://www.inkscape.org/namespace/inkscape/extension"> | ||
<_name>Convert to localized Braille</_name> | ||
|
||
<id>org.inkscape.TextBrailleL18n</id> | ||
<dependency type="executable" location="extensions">text_braille_l18n.py</dependency> | ||
|
||
<param name="locale" gui-text="Localization:" type="optiongroup" appearance="combo"> | ||
<option value="en">ASCII (English)</option> | ||
<option value="es">Spanish</option> | ||
</param> | ||
|
||
<effect> | ||
<object-type>all</object-type> | ||
<effects-menu> | ||
<submenu name="Text"/> | ||
</effects-menu> | ||
</effect> | ||
<script> | ||
<command reldir="extensions" interpreter="python">text_braille_l18n.py</command> | ||
</script> | ||
</inkscape-extension> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
|
||
__version__ = "0.0.1" | ||
|
||
import inkex | ||
|
||
def en_char_map(char): | ||
try: | ||
# https://en.wikipedia.org/wiki/Braille_ASCII#Braille_ASCII_values | ||
mapint = "A1B'K2L@CIF/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)=".index(char.upper()) | ||
except ValueError: | ||
return char | ||
return chr(mapint + 0x2801) | ||
|
||
def es_char_map(char): | ||
# https://es.wikipedia.org/wiki/Braille_espa%C3%B1ol | ||
if char.isnumeric(): | ||
return chr({ | ||
# numbers | ||
"1": 0x2801, | ||
"2": 0x2803, | ||
"3": 0x2809, | ||
"4": 0x2819, | ||
"5": 0x2811, | ||
"6": 0x280B, | ||
"7": 0x281b, | ||
"8": 0x2813, | ||
"9": 0x280a, | ||
"0": 0x281a, | ||
}[char]) | ||
try: | ||
return chr({ | ||
# letters | ||
"A": 0x2801, | ||
"B": 0x2803, | ||
"C": 0x2809, | ||
"D": 0x2819, | ||
"E": 0x2811, | ||
"F": 0x280B, | ||
"G": 0x281b, | ||
"H": 0x2813, | ||
"I": 0x280a, | ||
"J": 0x281a, | ||
"K": 0x2805, | ||
"L": 0x2807, | ||
"M": 0x280d, | ||
"N": 0x281d, | ||
"Ñ": 0x283b, | ||
"O": 0x2815, | ||
"P": 0x280f, | ||
"Q": 0x281f, | ||
"R": 0x2817, | ||
"S": 0x280e, | ||
"T": 0x281e, | ||
"U": 0x2825, | ||
"V": 0x2827, | ||
"W": 0x283a, | ||
"X": 0x282d, | ||
"Y": 0x283d, | ||
"Z": 0x2835, | ||
"Á": 0x2837, | ||
"É": 0x282e, | ||
"Í": 0x280c, | ||
"Ó": 0x282c, | ||
"Ú": 0x283e, | ||
"Ü": 0x2833, | ||
|
||
# signs | ||
"&": 0x282f, | ||
".": 0x2804, | ||
",": 0x2802, | ||
";": 0x2806, | ||
"¿": 0x2822, | ||
"?": 0x2822, | ||
"¡": 0x2816, | ||
"!": 0x2816, | ||
'"': 0x2826, | ||
"(": 0x2823, | ||
")": 0x281c, | ||
"-": 0x2824, | ||
"*": 0x2814, | ||
|
||
# prefixes | ||
chr(15): 0x2828, # uppercase prefix: https://codepoints.net/U+000F | ||
"#": 0x283c, # numerical prefix | ||
}[char.upper()]) | ||
except KeyError: | ||
return char | ||
|
||
LOCALE_CHARMAPS = { | ||
"en": en_char_map, | ||
"es": es_char_map, | ||
} | ||
|
||
class BrailleL18n(inkex.TextExtension): | ||
"""Convert to Braille giving a localized map of replacements.""" | ||
def add_arguments(self, pars): | ||
pars.add_argument( | ||
"-l", "--locale", type=str, dest="locale", default="en", | ||
choices=LOCALE_CHARMAPS.keys(), | ||
help="Locale to use converting to Braille.", | ||
) | ||
|
||
def process_chardata(self, text): | ||
"""Replaceable chardata method for processing the text.""" | ||
return ''.join(map(LOCALE_CHARMAPS[self.options.locale], text)) | ||
|
||
if __name__ == '__main__': | ||
BrailleL18n().run() |