From 6044728197a7f7091aea6d370baaffb3318d9e5b Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Thu, 13 May 2021 23:04:49 +0700 Subject: I use the script to generate script --- utils/README.md | 14 +++++- utils/draw_syllable.py | 115 ++++++++++++++++++++++++++++++++++++++++++++++ utils/parse-syllable.raku | 114 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 utils/draw_syllable.py create mode 100644 utils/parse-syllable.raku diff --git a/utils/README.md b/utils/README.md index 035e9c9..b0b326c 100644 --- a/utils/README.md +++ b/utils/README.md @@ -4,8 +4,20 @@ These are scripts that help me conlang easier. These scripts are licensed under GPLv3 license. +## Word generation + +Requirements: raku + Usage: -```raku +```sh raku genwords.raku ``` + +## Generating glyphs + +Requirements: raku (JSON::Tiny), python3 (svgutils) + +```sh +raku parse-syllable.raku | python3 draw_syllable.py +``` diff --git a/utils/draw_syllable.py b/utils/draw_syllable.py new file mode 100644 index 0000000..589e32a --- /dev/null +++ b/utils/draw_syllable.py @@ -0,0 +1,115 @@ +# Generate syllables from romanization +# Copyright (C) 2021 Ngô Ngọc Đức Huy +# +# This file is part of Hàësdáïga utils. +# +# Hàësdáïga utils 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. +# +# Hàësdáïga utils 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 Hàësdáïga utils. If not, see . +from json import loads + +import svgutils.transform as svg + +glyphs = loads(input()) +offset = 0 +GLYPH_SIZE = ("800px", "800px") +TEXT_SIZE = (f"{len(glyphs) * 900}px", "800px") + +background = svg.fromstring(f""" + + + +""") +background.set_size(TEXT_SIZE) + + +def prepare_letter(name): + glyph_svg = svg.fromfile(f'../assets/haasdaiga/{name}.svg') + glyph_svg.set_size(GLYPH_SIZE) + glyph_root = glyph_svg.getroot() + return glyph_root + +for glyph in glyphs: + if glyph['type'] == 'punctuation': + name = glyph['name'] + glyph_root = prepare_letter(name) + glyph_root.moveto(offset, 0) + background.append([glyph_root]) + else: + C1 = glyph['C1'] + C2 = glyph['C2'] + V1 = glyph['V1'] + V2 = glyph['V2'] + T = glyph['T'] + + C1_root = prepare_letter(C1) + if V1 == 'y' and T == 'level': + C1_root.moveto(offset, 0) + if C2 is not None: + C2_root = prepare_letter(C2) + C1_root.scale(0.5, 1) + C2_root.scale(0.5, 1) + C2_root.moveto(offset + 400, 0) + background.append([C2_root]) + background.append([C1_root]) + else: + if C2 is None: + C1_root.scale(1, 0.5) + C1_root.moveto(offset, 0) + background.append([C1_root]) + else: + C2_root = prepare_letter(C2) + C1_root.scale(0.5, 0.5) + C2_root.scale(0.5, 0.5) + C1_root.moveto(offset, 0) + C2_root.moveto(offset + 400, 0) + background.append([C1_root, C2_root]) + if V1 != 'y': + V1_root = prepare_letter(V1) + if T != 'level': + T_root = prepare_letter(T) + if V2 is not None: + V2_root = prepare_letter(V2) + V1_root.scale(1/3, 0.5) + V2_root.scale(1/3, 0.5) + T_root.scale(1/3, 0.5) + V1_root.moveto(offset, 400) + V2_root.moveto(offset + 2 * 800/3, 400) + T_root.moveto(offset + 800/3, 400) + background.append([V1_root, V2_root, T_root]) + else: + V1_root.scale(0.5, 0.5) + T_root.scale(0.5, 0.5) + V1_root.moveto(offset, 400) + T_root.moveto(offset + 400, 400) + background.append([V1_root, T_root]) + else: + if V2 is not None: + V2_root = prepare_letter(V2) + V1_root.scale(0.5, 0.5) + V2_root.scale(0.5, 0.5) + V1_root.moveto(offset, 400) + V2_root.moveto(offset + 400, 400) + background.append([V1_root, V2_root]) + else: + V1_root.scale(1, 0.5) + V1_root.moveto(offset, 400) + background.append([V1_root]) + else: + if T != 'level': + T_root = prepare_letter(T) + T_root.scale(1, 0.5) + T_root.moveto(offset, 400) + background.append([T_root]) + offset += 900 + +background.save('output.svg') diff --git a/utils/parse-syllable.raku b/utils/parse-syllable.raku new file mode 100644 index 0000000..22ff38b --- /dev/null +++ b/utils/parse-syllable.raku @@ -0,0 +1,114 @@ +# Parser for word syllables. +# Copyright (C) 2021 Ngô Ngọc Đức Huy +# +# This file is part of Hàësdáïga utils. +# +# Hàësdáïga utils 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. +# +# Hàësdáïga utils 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 Hàësdáïga utils. If not, see . +use JSON::Tiny; + +grammar Syllable { + token TOP { } + + token onset { * } + token nucleus { ? } + token coda { * } + + token vowel { <[aeiouy]>} + token rise-vowel { <[áéíóúý]>} + token fall-vowel { <[àèìòùỳ]>} + token first-vowel { [ | | ] } + token second-vowel { [ | '~' ] } + token consonant { <[bcdfghjlmnprstvwz']> } +} + +class Parser { + method nucleus ($/) { + make ($.made, $ ?? + $.made !! Nil).flat + } + method first-vowel ($/) { + make $ ?? $.made !! ( + $ ?? $.made !! $.made); + } + method rise-vowel ($/) { + given $/ { + when 'á' { make ('a', 'rising')} + when 'é' { make ('e', 'rising')} + when 'í' { make ('i', 'rising')} + when 'ó' { make ('o', 'rising')} + when 'ú' { make ('u', 'rising')} + when 'ý' { make ('y', 'rising')} + } + } + method fall-vowel ($/) { + given $/ { + when 'à' { make ('a', 'falling')} + when 'è' { make ('e', 'falling')} + when 'ì' { make ('i', 'falling')} + when 'ò' { make ('o', 'falling')} + when 'ù' { make ('u', 'falling')} + when 'ỳ' { make ('y', 'falling')} + } + } + method vowel ($/) { + make ($/.words.join, 'level') + } + method second-vowel ($/) { make $/.words.join } + method coda ($/) {make $ ?? $.join !! Nil} +} + +sub extras ($char) { + my %parsing; + %parsing{"type"} = "punctuation"; + %parsing{"name"} = do given $char { + when ',' { 'comma' } + when ':' { 'colon' } + when '!' { 'exclam' } + when '(' { 'parenleft' } + when ')' { 'parenright' } + when '.' { 'period' } + when '?' { 'question' } + }; + return %parsing +} + +sub parse-one ($word) { + if $word ∈ <. , ? ! ( ) :> { + return extras($word); + } + my $C1 = Syllable.parse($word).join; + my $C2 = Syllable.parse( + $word, actions => Parser).made; + my ($V1, $T, $V2) = Syllable.parse( + $word, actions => Parser).made; + if $V2 eqv '~' { $V2 = 'long' } + if $C1 eqv "'" { $C1 = 'glottal'} + + my %parsing; + %parsing{"type"} = "syllable"; + %parsing{"C1"} = $C1; + %parsing{"C2"} = $C2; + %parsing{"V1"} = $V1; + %parsing{"V2"} = $V2; + %parsing{"T" } = $T ; + return %parsing +} + +sub MAIN ($phrase) { + my @list; + for $phrase.words -> $word { + @list.push(parse-one($word)) + } + say to-json @list; +} -- cgit 1.4.1