├── fontconfig.vapi ├── scripts ├── __init__.py ├── linux_build.py ├── version.py ├── fuzzbf.py ├── fuzzsvg.py ├── run.py ├── update_translations.py ├── translations.py ├── configfile.py └── release.sh ├── resources ├── ucd.sqlite ├── codepages.sqlite ├── Roboto-Regular.ttf ├── birdfont.py ├── linux │ ├── 128x128 │ │ └── birdfont.png │ ├── 256x256 │ │ └── birdfont.png │ ├── 48x48 │ │ └── birdfont.png │ ├── birdfont_window_icon.png │ ├── birdfont.desktop │ ├── birdfont.xml │ ├── birdfont.1 │ ├── birdfont-export.1 │ ├── birdfont-import.1 │ ├── birdfont-autotrace.1 │ └── birdfont.appdata.xml ├── birdfont-crashdb.conf └── source_birdfont.py ├── webkit2gtk-3.0.deps ├── .gitignore ├── birdfont.sh ├── birdfont-export.sh ├── birdfont-import.sh ├── birdfont-test.sh ├── birdfont-autotrace.sh ├── birdfont-debug.sh ├── AUTHORS ├── birdfont-import-debug.sh ├── libbirdgems └── birdgems.vala ├── TRANSLATORS ├── android.vapi ├── uninstall ├── libbirdfont ├── String.vala ├── SubMenu.vala ├── OpenFontFormat │ ├── Kern.vala │ ├── PairFormat1.vala │ ├── CmapSubtable.vala │ ├── CvtTable.vala │ ├── Feature.vala │ ├── GdefTable.vala │ ├── OtfInputStream.vala │ ├── GaspTable.vala │ ├── Alternate.vala │ ├── ContextualLigatureCollection.vala │ ├── KerningPair.vala │ ├── CmapSubtableFormat0.vala │ ├── FeatureList.vala │ ├── OffsetTable.vala │ ├── CmapSubtableFormat12.vala │ ├── MaxpTable.vala │ ├── KernSplitter.vala │ ├── OpenFontFormatWriter.vala │ ├── KernSubtable.vala │ ├── Lookup.vala │ ├── CligFeature.vala │ ├── Ligature.vala │ ├── OtfTable.vala │ └── Lookups.vala ├── Renderer │ ├── LineTextArea.vala │ ├── FontCache.vala │ └── CachedFont.vala ├── MergeTask.vala ├── BackupDir.vala ├── Stop.vala ├── ZoomView.vala ├── Dialog.vala ├── BezierPoints.vala ├── Kerning.vala ├── OtfTags.vala ├── SaveDialogListener.vala ├── ScaledBackgroundPart.vala ├── EmptyTab.vala ├── Gradient.vala ├── OverwriteBfFile.vala ├── Allocation.vala ├── UniRange.vala ├── TextListener.vala ├── Screen.vala ├── Headline.vala ├── OverWriteDialogListener.vala ├── FileChooser.vala ├── ToolItem.vala ├── StrokeTask.vala ├── Tab.vala ├── ThemeTools.vala ├── ExportCallback.vala ├── GlyphSelection.vala ├── GuideTab.vala ├── ToolCollection.vala ├── Test.vala ├── PointSelection.vala ├── FontName.vala ├── MenuAction.vala ├── Task.vala ├── GlyphTable.vala ├── OtfLabel.vala ├── PathList.vala ├── SpacingClass.vala ├── Button.vala ├── BackgroundTab.vala ├── SpacingClassTools.vala ├── CharacterInfo.vala ├── ScaledBackgrounds.vala ├── ColorTool.vala ├── LanguageSelectionTab.vala ├── BackgroundSelection.vala ├── NativeWindow.vala ├── Widget.vala ├── MenuItem.vala ├── RectangleTool.vala ├── SaveCallback.vala ├── OrientationTool.vala ├── SpacingTools.vala ├── GlyphMaster.vala ├── PreviewTools.vala ├── HiddenTools.vala ├── KerningStrings.vala ├── SvgStyle.vala ├── GlyphCanvas.vala ├── Intersection.vala ├── CheckBox.vala ├── MessageDialog.vala ├── AlternateSets.vala ├── BackgroundSelectionTool.vala └── SvgTransform.vala ├── birdfont-export └── BirdfontExport.vala ├── birdfont-import └── BirdFontImport.vala ├── birdfont └── Main.vala ├── .travis.yml └── README.md /fontconfig.vapi: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/ucd.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/birdfont/master/resources/ucd.sqlite -------------------------------------------------------------------------------- /resources/codepages.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/birdfont/master/resources/codepages.sqlite -------------------------------------------------------------------------------- /resources/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/birdfont/master/resources/Roboto-Regular.ttf -------------------------------------------------------------------------------- /resources/birdfont.py: -------------------------------------------------------------------------------- 1 | def add_info(report, ui=None): 2 | report['SecretMessage'] = 'BirdFont error report.' 3 | -------------------------------------------------------------------------------- /webkit2gtk-3.0.deps: -------------------------------------------------------------------------------- 1 | atk 2 | gio-2.0 3 | cairo 4 | pango 5 | gdk-pixbuf-2.0 6 | gdk-3.0 7 | gtk+-3.0 8 | libsoup-2.4 9 | -------------------------------------------------------------------------------- /resources/linux/128x128/birdfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/birdfont/master/resources/linux/128x128/birdfont.png -------------------------------------------------------------------------------- /resources/linux/256x256/birdfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/birdfont/master/resources/linux/256x256/birdfont.png -------------------------------------------------------------------------------- /resources/linux/48x48/birdfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/birdfont/master/resources/linux/48x48/birdfont.png -------------------------------------------------------------------------------- /resources/linux/birdfont_window_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/birdfont/master/resources/linux/birdfont_window_icon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.pyc 3 | .doit.db 4 | libbirdfont/Config.vala 5 | scripts/config.py 6 | libbirdgems.vapi 7 | libbirdfont.vapi 8 | *~ 9 | -------------------------------------------------------------------------------- /resources/birdfont-crashdb.conf: -------------------------------------------------------------------------------- 1 | birdfont = { 2 | 'impl' : 'launchpad', 3 | 'project' : 'birdfont', 4 | 'bug_pattern_base' : None, 5 | } 6 | -------------------------------------------------------------------------------- /birdfont.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="./build/:./build/bin:$LD_LIBRARY_PATH" 3 | PKG_PATH=$(dirname "$(readlink -f "$0")") 4 | cd "${PKG_PATH}" 5 | ./build/bin/birdfont "$@" 6 | -------------------------------------------------------------------------------- /birdfont-export.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="./build/bin:$LD_LIBRARY_PATH" 3 | PKG_PATH=$(dirname "$(readlink -f "$0")") 4 | cd "${PKG_PATH}" 5 | 6 | ./build/bin/birdfont-export "$@" 7 | -------------------------------------------------------------------------------- /birdfont-import.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="./build/bin:$LD_LIBRARY_PATH" 3 | PKG_PATH=$(dirname "$(readlink -f "$0")") 4 | cd "${PKG_PATH}" 5 | 6 | ./build/bin/birdfont-import "$@" 7 | -------------------------------------------------------------------------------- /birdfont-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="./build/:./build/bin:$LD_LIBRARY_PATH" 3 | PKG_PATH=$(dirname "$(readlink -f "$0")") 4 | cd "${PKG_PATH}" 5 | ./build/bin/birdfont-test "$@" 6 | -------------------------------------------------------------------------------- /birdfont-autotrace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="./build/bin:$LD_LIBRARY_PATH" 3 | PKG_PATH=$(dirname "$(readlink -f "$0")") 4 | cd "${PKG_PATH}" 5 | 6 | ./build/bin/birdfont-autotrace "$@" 7 | -------------------------------------------------------------------------------- /birdfont-debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="./build/:./build/bin:$LD_LIBRARY_PATH" 3 | PKG_PATH=$(dirname "$(readlink -f "$0")") 4 | cd "${PKG_PATH}" 5 | gdb ./build/bin/birdfont -ex "run "$@"" 6 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Authors of BirdFont in chronological order: 2 | Johan Mattsson 3 | Alexandre Prokoudine 4 | Eduardo Schettino 5 | Zhantong Zhang 6 | Clemens Lang 7 | Hideki Yamane 8 | Rene Mensen 9 | Marko Jovanovac 10 | -------------------------------------------------------------------------------- /resources/source_birdfont.py: -------------------------------------------------------------------------------- 1 | import apport.packaging 2 | 3 | def add_info(report, ui=None): 4 | if not apport.packaging.is_distro_package(report['Package'].split()[0]): 5 | report['CrashDB'] = 'birdfont' 6 | -------------------------------------------------------------------------------- /birdfont-import-debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="./build/bin:$LD_LIBRARY_PATH" 3 | PKG_PATH=$(dirname "$(readlink -f "$0")") 4 | cd "${PKG_PATH}" 5 | 6 | gdb ./build/bin/birdfont-import -ex "run "$@"" 7 | 8 | -------------------------------------------------------------------------------- /libbirdgems/birdgems.vala: -------------------------------------------------------------------------------- 1 | namespace Gems { 2 | 3 | [CCode (cname = "fit_bezier_curve_to_line")] 4 | public extern static int fit_bezier_curve_to_line (double[] lines, double error, out double[] bezier_curve); 5 | 6 | } 7 | -------------------------------------------------------------------------------- /TRANSLATORS: -------------------------------------------------------------------------------- 1 | Sven Santegoeds 2 | Robert Kabinger 3 | Marc-Philipp Beuter 4 | Manuela Silva 5 | Zhantong Zhang 6 | Johan Mattsson 7 | Paul Pricootz 8 | Adolfo Jayme Barrientos 9 | Fabio Goto 10 | Pavel Fric 11 | TranSuppo 12 | 13 | See http://pootle.locamotion.org/about/contributors/ for a recent list of 14 | translators. 15 | 16 | -------------------------------------------------------------------------------- /resources/linux/birdfont.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Birdfont 3 | Name[ru]=Birdfont 4 | Comment=Font editor 5 | Comment[ru]=Редактор шрифтов 6 | Exec=birdfont %U 7 | Icon=birdfont 8 | StartupWMClass=birdfont 9 | Terminal=false 10 | Type=Application 11 | GenericName=Font Editor 12 | Categories=Graphics;VectorGraphics; 13 | Keywords=Font; 14 | Keywords[ja]=フォント; 15 | -------------------------------------------------------------------------------- /scripts/linux_build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from os import path 3 | from run import run 4 | 5 | if not path.isfile('./build/configured'): 6 | run("""./configure \ 7 | --valac-flags='--pkg gdk-pixbuf-2.0 --pkg gtk+-3.0' \ 8 | --cflags='$(pkg-config --cflags gdk-pixbuf-2.0)' \ 9 | --ldflags='$(pkg-config --libs gdk-pixbuf-2.0)'""") 10 | 11 | run('./build.py') 12 | print ("Done") 13 | -------------------------------------------------------------------------------- /android.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cname = "ANDROID_LOG_WARN", cheader_filename = "android/log.h")] 2 | public extern static const int ANDROID_LOG_WARN; 3 | 4 | [CCode (cname = "ANDROID_LOG_INFO", cheader_filename = "android/log.h")] 5 | public extern static const int ANDROID_LOG_INFO; 6 | 7 | [CCode (cname = "__android_log_print", cheader_filename = "android/log.h")] 8 | public extern static int __android_log_print (int prio, string tag, string fmt, ...); 9 | -------------------------------------------------------------------------------- /uninstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import subprocess 4 | from scripts.run import run 5 | 6 | if not os.path.exists ("build/configured"): 7 | print ("Project is not configured") 8 | exit (1) 9 | 10 | if not os.path.exists ("build/installed"): 11 | print ("Project is not installed") 12 | exit (1) 13 | 14 | f = open('build/installed') 15 | for file in iter(f): 16 | print ('Removing ' + file.replace ('\n', '')) 17 | run ('rm ' + file) 18 | 19 | f.close() 20 | -------------------------------------------------------------------------------- /resources/linux/birdfont.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BirdFont file 5 | Font 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /resources/linux/birdfont.1: -------------------------------------------------------------------------------- 1 | .TH BIRDFONT 1 LOCAL 2 | 3 | .SH NAME 4 | birdfont - font editor 5 | .SH SYNOPSIS 6 | .B birdfont [file] [options] 7 | .SH DESCRIPTION 8 | birdfont lets you edit and create fonts. 9 | 10 | See https://birdfont.org 11 | .SH OPTIONS 12 | .TP 13 | \-c, \--show-coordinates 14 | show coordinate in glyph view 15 | .TP 16 | \-e, \--exit 17 | exit if a testcase failes 18 | .TP 19 | \-f, \--fatal-warning 20 | treat warnings as fatal 21 | .TP 22 | \-h, \--help 23 | show command line options 24 | .TP 25 | \-s, \--slow 26 | sleep between each command in test suite 27 | .TP 28 | \-t [testcase] 29 | run tests 30 | .SH AUTHOR 31 | Johan Mattsson 32 | 33 | -------------------------------------------------------------------------------- /resources/linux/birdfont-export.1: -------------------------------------------------------------------------------- 1 | .TH BIRDFONT-EXPORT 1 LOCAL 2 | 3 | .SH NAME 4 | birdfont-export - generate TTF, EOT and SVG files from BIRDFONT files 5 | .SH SYNOPSIS 6 | .B birdfont-export [options] file 7 | .SH DESCRIPTION 8 | birdfont-export generates fonts that can be installed and on 9 | your computer or deployed on your website. 10 | 11 | See https://birdfont.org for use cases. 12 | .SH OPTIONS 13 | .TP 5 14 | \--filter [characters] 15 | Include only these characters 16 | .TP 17 | \-h, \--help 18 | Print command line options. 19 | .TP 20 | \-o, \--output [directory] 21 | Write files to this directory 22 | .TP 23 | \-s, \--svg 24 | Write SVG font 25 | .TP 26 | \-t, \--ttf 27 | Write TTF and EOT fonts 28 | .SH AUTHOR 29 | Johan Mattsson 30 | -------------------------------------------------------------------------------- /libbirdfont/String.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** Boxed string class. */ 18 | public class String : GLib.Object { 19 | public string c_str; 20 | 21 | public String (string data) { 22 | this.c_str = data; 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /resources/linux/birdfont-import.1: -------------------------------------------------------------------------------- 1 | .TH BIRDFONT-IMPORT 1 LOCAL 2 | 3 | .SH NAME 4 | birdfont-import - Create a font from SVG files 5 | .SH SYNOPSIS 6 | .B birdfont-import birdfont-file svg-files ... 7 | .SH DESCRIPTION 8 | birdfont-import 9 | birdfont-import will generate a birdfont file from a set of SVG images. 10 | The command assumes that the file name denotes either a single character 11 | or a Unicode value on the form U+XX where XX is the Unicode number in 12 | hexadecimal format. 13 | 14 | A drawing saved as "a.svg" will be added to the glyph "a" when you run: 15 | birdfont-import typeface.bf a.svg 16 | 17 | A drawing saved as "U+62.svg" will be added to "b" when you run: 18 | birdfont-import typeface.bf U+62.svg 19 | 20 | See also birdfont-export for creating SVG, EOT and TTF fonts from the 21 | birdfont file. 22 | 23 | .SH AUTHOR 24 | Johan Mattsson 25 | -------------------------------------------------------------------------------- /birdfont-export/BirdfontExport.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | using BirdFont; 19 | 20 | public static int main (string[] arg) { 21 | return run_export (arg); 22 | } 23 | -------------------------------------------------------------------------------- /libbirdfont/SubMenu.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using B; 17 | 18 | namespace BirdFont { 19 | public class SubMenu : GLib.Object { 20 | public Gee.ArrayList items; 21 | 22 | public SubMenu () { 23 | items = new Gee.ArrayList (); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/Kern.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class Kern : GLib.Object { 18 | public uint16 left; 19 | public uint16 right; 20 | public int16 kerning; 21 | 22 | public Kern (uint16 l, uint16 r, int16 k) { 23 | left = l; 24 | right = r; 25 | kerning = k; 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /birdfont-import/BirdFontImport.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | using BirdFont; 19 | 20 | /** Import multiple SVG files to a BF file. */ 21 | public static int main (string[] arg) { 22 | return run_import (arg); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /resources/linux/birdfont-autotrace.1: -------------------------------------------------------------------------------- 1 | .TH BIRDFONT-AUTOTRACE 1 LOCAL 2 | 3 | .SH NAME 4 | birdfont-autotrace - Convert raster image to vector graphics 5 | .SH SYNOPSIS 6 | .B birdfont-import birdfont-file svg-files ... 7 | .SH DESCRIPTION 8 | birdfont-autotrace 9 | birdfont-autotrace will generate SVG files from raster images. For an 10 | image with the name example.png will a file with the name example.svg be 11 | generated. 12 | 13 | .SH OPTIONS 14 | .TP 5 15 | \-c, \--cutoff 16 | brightness cutoff, from 0.001 to 2, the default value is 1 17 | .TP 18 | \-d, \--details 19 | details, from 0.001 to 9.999, the default value is 1 20 | .TP 21 | \-h, \--help 22 | print help message 23 | .TP 24 | \-q, \--quadratic 25 | use quadratic control points instead of cubic control points. 26 | .TP 27 | \-s, \--simplification 28 | path simplification, from 0.001 to 1, the default value is 0.5 29 | 30 | .SH AUTHOR 31 | Johan Mattsson 32 | 33 | -------------------------------------------------------------------------------- /libbirdfont/Renderer/LineTextArea.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class LineTextArea : TextArea { 21 | 22 | public LineTextArea (double size) { 23 | base (size); 24 | 25 | single_line = true; 26 | min_height = size; 27 | height = min_height; 28 | 29 | layout (); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /scripts/version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Copyright (C) 2013, 2014 Johan Mattsson 4 | 5 | This library is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as 7 | published by the Free Software Foundation; either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | """ 15 | 16 | VERSION = '2.29.0' 17 | SO_VERSION_MAJOR = '36' 18 | SO_VERSION_MINOR = '0' 19 | SO_VERSION = SO_VERSION_MAJOR + '.' + SO_VERSION_MINOR 20 | 21 | LIBBIRDGEMS_SO_VERSION_MAJOR = '0' 22 | LIBBIRDGEMS_SO_VERSION_MINOR = '0' 23 | LIBBIRDGEMS_SO_VERSION = LIBBIRDGEMS_SO_VERSION_MAJOR + '.' + LIBBIRDGEMS_SO_VERSION_MINOR; 24 | -------------------------------------------------------------------------------- /scripts/fuzzbf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import subprocess 4 | from os import path 5 | 6 | from run import run 7 | 8 | def fuzz_import(): 9 | fuzz_bf ('birdfont-test/testfont.bf') 10 | 11 | def fuzz_bf (file): 12 | run ("mkdir -p build/fuzz") 13 | run ("mkdir -p build/fuzz/bugs") 14 | run ("radamsa " + file + " > build/fuzz/font.bf") 15 | 16 | cmd = "./birdfont-test.sh BF build/fuzz/font.bf" 17 | print('Running: ' + cmd) 18 | process = subprocess.Popen (cmd, shell=True) 19 | process.communicate()[0] 20 | if not process.returncode == 0: 21 | print("Error: " + cmd) 22 | print("A bug was found.") 23 | 24 | i = 0 25 | while path.isfile ('build/bugs/font_' + str(i) + '.bf'): 26 | i = i + 1 27 | 28 | run ('mv build/fuzz/font.bf attic/fuzz/bugs/font_' + str(i) + '.bf') 29 | 30 | run ("rm -f build/fuzz/font.svg") 31 | 32 | while True: 33 | fuzz_import () 34 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/PairFormat1.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Math; 15 | 16 | namespace BirdFont { 17 | 18 | /** GSUB pairwise positioning format 1. 19 | * A class that stores kerning information for one letter. 20 | */ 21 | public class PairFormat1 : GLib.Object { 22 | public uint16 left = 0; 23 | public Gee.ArrayList pairs = new Gee.ArrayList (); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /libbirdfont/MergeTask.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | class MergeTask : StrokeTask { 20 | StrokeTool stroke_tool; 21 | 22 | public MergeTask () { 23 | base.none (); 24 | stroke_tool = new StrokeTool.with_task (this); 25 | } 26 | 27 | public override void run () { 28 | stroke_tool.merge_selected_paths (); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/CmapSubtable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public abstract class CmapSubtable : GLib.Object { 18 | public abstract ushort get_platform (); 19 | public abstract ushort get_encoding (); 20 | 21 | public abstract void generate_cmap_data (GlyfTable glyf_table) 22 | throws GLib.Error; 23 | 24 | public abstract FontData get_cmap_data (); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /libbirdfont/BackupDir.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class BackupDir : GLib.Object { 21 | public string folder_name; 22 | public string modification_time; 23 | 24 | public BackupDir (string folder_name, string modification_time) { 25 | this.folder_name = folder_name; 26 | this.modification_time = modification_time; 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /libbirdfont/Stop.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class Stop : GLib.Object { 21 | public Color color = Color.black (); 22 | public double offset = 0; 23 | 24 | public Stop () { 25 | } 26 | 27 | public Stop copy () { 28 | Stop s = new Stop (); 29 | s.color = color.copy (); 30 | s.offset = offset; 31 | return s; 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /libbirdfont/ZoomView.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | class ZoomView : GLib.Object { 18 | public double x; 19 | public double y; 20 | public double zoom; 21 | public WidgetAllocation allocation; 22 | 23 | public ZoomView (double x, double y, double zoom, WidgetAllocation allocation) { 24 | this.x = x; 25 | this.y = y; 26 | this.zoom = zoom; 27 | this.allocation = allocation; 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /scripts/fuzzsvg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import subprocess 4 | from os import path 5 | 6 | from run import run 7 | 8 | def fuzz_svg_import(): 9 | fuzz_svg ('birdfont-test/inkscape.svg') 10 | fuzz_svg ('birdfont-test/illustrator.svg') 11 | 12 | def fuzz_svg (file): 13 | run ("mkdir -p build/fuzz") 14 | run ("mkdir -p build/fuzz/bugs") 15 | run ("radamsa " + file + " > build/fuzz/a.svg") 16 | 17 | cmd = "./birdfont-test.sh SVG build/fuzz/a.svg" 18 | print('Running: ' + cmd) 19 | process = subprocess.Popen (cmd, shell=True) 20 | process.communicate()[0] 21 | if not process.returncode == 0: 22 | print("Error: " + cmd) 23 | print("A bug was found.") 24 | 25 | i = 0 26 | while path.isfile ('build/bugs/a_' + str(i) + '.svg'): 27 | i = i + 1 28 | 29 | run ('mv build/fuzz/a.svg attic/fuzz/bugs/a_' + str(i) + '.svg') 30 | 31 | run ("rm -f build/fuzz/a.svg") 32 | 33 | while True: 34 | fuzz_svg_import () 35 | -------------------------------------------------------------------------------- /scripts/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Copyright (C) 2013 Johan Mattsson 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | """ 18 | 19 | import subprocess 20 | 21 | def run(cmd): 22 | cmd = "sh -c \"" + cmd.replace ("\"", "\\\"") + "\"" 23 | process = subprocess.Popen (cmd, shell=True) 24 | process.communicate()[0] 25 | if not process.returncode == 0: 26 | print("Error: " + cmd) 27 | exit(1) 28 | -------------------------------------------------------------------------------- /libbirdfont/Dialog.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class Dialog : Widget { 20 | 21 | public bool visible { get; set; } 22 | 23 | public Dialog () { 24 | visible = false; 25 | } 26 | 27 | public override void draw (Context cr) { 28 | } 29 | 30 | public override double get_height () { 31 | return 0; 32 | } 33 | 34 | public override double get_width () { 35 | return 0; 36 | } 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/CvtTable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class CvtTable : OtfTable { 18 | 19 | public CvtTable () { 20 | id = "cvt "; 21 | } 22 | 23 | public override void parse (FontData dis) throws Error { 24 | } 25 | 26 | public void process () throws GLib.Error { 27 | FontData fd = new FontData (); 28 | 29 | fd.add_ushort (0); 30 | fd.pad (); 31 | 32 | this.font_data = fd; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /libbirdfont/BezierPoints.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** Bezier point container for the SVG parser. */ 18 | public class BezierPoints { 19 | public unichar type = '\0'; 20 | public unichar svg_type = '\0'; 21 | public double x0 = 0; 22 | public double y0 = 0; 23 | public double x1 = 0; 24 | public double y1 = 0; 25 | public double x2 = 0; 26 | public double y2 = 0; 27 | 28 | public string to_string () { 29 | return @"$((!)type.to_string ()) $x0,$y0 $x1,$y1 $x2,$y2 SVG:$((!)svg_type.to_string ())"; 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libbirdfont/Kerning.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using B; 17 | 18 | namespace BirdFont { 19 | 20 | public class Kerning : GLib.Object { 21 | public double val; 22 | public Glyph? glyph; 23 | 24 | public Kerning (double v) { 25 | val = v; 26 | glyph = null; 27 | } 28 | 29 | public Kerning.for_glyph (Glyph? g, double v) { 30 | val = v; 31 | glyph = g; 32 | } 33 | 34 | public Glyph get_glyph () { 35 | if (unlikely (glyph == null)) { 36 | warning ("No glyph"); 37 | return new Glyph (""); 38 | } 39 | 40 | return (!) glyph; 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /libbirdfont/OtfTags.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class OtfTags : GLib.Object { 18 | public Gee.ArrayList elements = new Gee.ArrayList (); 19 | 20 | public void add (string tag) { 21 | elements.add (tag); 22 | } 23 | 24 | public void remove (string tag) { 25 | while (elements.index_of (tag) > -1) { 26 | elements.remove (tag); 27 | } 28 | } 29 | 30 | public OtfTags copy () { 31 | OtfTags tags = new OtfTags (); 32 | 33 | foreach (string e in elements) { 34 | tags.add (e); 35 | } 36 | 37 | return tags; 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/Feature.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class Feature : GLib.Object { 18 | 19 | public string tag; 20 | public Lookups lookups; 21 | public Gee.ArrayList public_lookups = new Gee.ArrayList (); 22 | 23 | public Feature (string tag, Lookups lookups) { 24 | this.tag = tag; 25 | this.lookups = lookups; 26 | } 27 | 28 | public void add_feature_lookup (string lookup_token) { 29 | public_lookups.add (lookup_token); 30 | } 31 | 32 | public int get_public_lookups () { 33 | return public_lookups.size; 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /resources/linux/birdfont.appdata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.birdfont.birdfont 4 | GPL-3.0+ 5 | GPL-3.0+ 6 | birdfont 7 | Font editor 8 | 9 | 10 | BirdFont is a font editor which can generate fonts in TTF, 11 | EOT and SVG format. 12 | 13 | 14 | https://birdfont.org/ 15 | https://birdfont.org/ 16 | https://birdfont.org/bugtracker/my_view_page.php 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Birdfont on Linux 25 | https://birdfont.org/images/birdfont_font_editor.png 26 | 27 | 28 | 29 | birdfont 30 | 31 | johan.mattsson.m@gmail.com 32 | 33 | -------------------------------------------------------------------------------- /scripts/update_translations.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import subprocess 3 | import os 4 | 5 | def task_update_translations (): 6 | subprocess.check_output ("xgettext --language=vala --keyword=t_ --add-comments=/ --from-code=utf-8 --output=./po/birdfont.pot ./libbirdfont/*.vala ./birdfont/*.vala ./birdfont-export/*.vala ./birdfont-autotrace/*.vala", shell=True) 7 | 8 | for file in os.listdir('./po'): 9 | if file == "birdfont.pot": continue 10 | 11 | try: 12 | if file.index ('.po') == -1: continue 13 | except: 14 | continue 15 | 16 | loc = file.replace (".po", "") 17 | d = "./po/" + loc + ".po" 18 | 19 | subprocess.check_output ("wget -O build/" + loc + ".po.zip http://pootle.locamotion.org/" + loc + "/birdfont/export/zip", shell=True) 20 | subprocess.check_output ("unzip build/" + loc + ".po.zip", shell=True) 21 | subprocess.check_output ("mv " + loc + ".po " + d, shell=True) 22 | 23 | subprocess.check_output ("msgmerge " + d + " ./po/birdfont.pot > " + loc + ".po.new", shell=True) 24 | subprocess.check_output ("mv " + loc + ".po.new " + d, shell=True) 25 | 26 | return { 27 | 'actions': ['echo "done updating translations"'], 28 | } 29 | 30 | 31 | task_update_translations () 32 | -------------------------------------------------------------------------------- /libbirdfont/SaveDialogListener.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class SaveDialogListener : GLib.Object { 18 | 19 | public signal void signal_save (); 20 | public signal void signal_discard (); 21 | public signal void signal_cancel (); 22 | 23 | public string message; 24 | public string discard_message; 25 | public string save_message; 26 | 27 | public SaveDialogListener () { 28 | this.message = t_("Save?"); 29 | this.save_message = t_("Save"); 30 | this.discard_message = t_("Discard"); 31 | } 32 | 33 | public void save () { 34 | signal_save (); 35 | } 36 | 37 | public void discard () { 38 | signal_discard (); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /libbirdfont/ScaledBackgroundPart.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | using Gee; 18 | 19 | namespace BirdFont { 20 | 21 | public class ScaledBackgroundPart : GLib.Object { 22 | public double scale; 23 | public int offset_x; 24 | public int offset_y; 25 | public ImageSurface image; 26 | 27 | public ScaledBackgroundPart (ImageSurface image, double scale, int offset_x, int offset_y) { 28 | this.image = image; 29 | this.scale = scale; 30 | this.offset_x = offset_x; 31 | this.offset_y = offset_y; 32 | } 33 | 34 | public double get_scale () { 35 | return scale; 36 | } 37 | 38 | public ImageSurface get_image () { 39 | return image; 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /birdfont/Main.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2014 Johan Mattsson 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | using BirdFont; 19 | 20 | public static int main (string[] arg) { 21 | GtkWindow native_window; 22 | MainWindow window; 23 | BirdFont.BirdFont birdfont; 24 | 25 | birdfont = new BirdFont.BirdFont (); 26 | birdfont.init (arg, null, "birdfont", null); 27 | Gtk.init (ref arg); 28 | 29 | window = new MainWindow (); 30 | native_window = new GtkWindow ("birdfont"); 31 | 32 | window.set_native (native_window); 33 | native_window.init (); 34 | birdfont.load_font_from_command_line (); 35 | 36 | Gtk.main (); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /libbirdfont/EmptyTab.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class EmptyTab : FontDisplay { 20 | 21 | string name; 22 | string label; 23 | 24 | public EmptyTab (string name, string label) { 25 | this.name = name; 26 | this.label = label; 27 | } 28 | 29 | public override string get_name () { 30 | return name; 31 | } 32 | 33 | public override string get_label () { 34 | return label; 35 | } 36 | 37 | public override void draw (WidgetAllocation allocation, Context cr) { 38 | cr.save (); 39 | Theme.color (cr, "Default Background"); 40 | cr.rectangle (0, 0, allocation.width, allocation.height); 41 | cr.fill (); 42 | cr.restore (); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/GdefTable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class GdefTable : OtfTable { 18 | 19 | public GdefTable () { 20 | id = "GDEF"; 21 | } 22 | 23 | public override void parse (FontData dis) throws Error { 24 | } 25 | 26 | public void process () throws GLib.Error { 27 | FontData fd = new FontData (); 28 | 29 | fd.add_ulong (0x00010002); 30 | fd.add_ushort (0); // class def 31 | fd.add_ushort (0); // attach list 32 | fd.add_ushort (0); // ligature carret 33 | fd.add_ushort (0); // mark attach 34 | fd.add_ushort (0); // mark glyf 35 | fd.add_ushort (0); // mark glyf set def 36 | 37 | fd.pad (); 38 | 39 | this.font_data = fd; 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /libbirdfont/Gradient.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class Gradient : GLib.Object { 21 | public double x1; 22 | public double y1; 23 | public double x2; 24 | public double y2; 25 | 26 | public Gee.ArrayList stops; 27 | 28 | public int id = -1; 29 | 30 | public Gradient () { 31 | x1 = 0; 32 | y1 = 0; 33 | x2 = 0; 34 | y2 = 0; 35 | stops = new Gee.ArrayList (); 36 | } 37 | 38 | public Gradient copy () { 39 | Gradient g = new Gradient (); 40 | g.x1 = x1; 41 | g.y1 = y1; 42 | g.x2 = x2; 43 | g.y2 = y2; 44 | 45 | foreach (Stop s in stops) { 46 | g.stops.add (s.copy ()); 47 | } 48 | 49 | return g; 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /libbirdfont/OverwriteBfFile.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class OverwriteBfFile : QuestionDialog { 20 | 21 | Button replace; 22 | Button cancel; 23 | 24 | public OverwriteBfFile (SaveCallback save_callback) { 25 | base(t_("This file already exists. Do you want to replace it?")); 26 | 27 | replace = new Button (t_("Replace")); 28 | replace.action.connect (() => { 29 | MainWindow.hide_dialog (); 30 | save_callback.save (); 31 | }); 32 | add_button (replace); 33 | 34 | cancel = new Button (t_("Cancel")); 35 | cancel.action.connect (() => { 36 | save_callback.is_done = true; 37 | MainWindow.hide_dialog (); 38 | }); 39 | add_button (cancel); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /scripts/translations.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Copyright (C) 2013 Johan Mattsson 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | """ 18 | 19 | import glob 20 | 21 | try: 22 | from scripts.run import run 23 | except ImportError: 24 | from run import run 25 | 26 | def compile_translations (): 27 | for f_name in glob.glob('po/*.po'): 28 | lang = f_name.replace ("po/", "").replace (".po", "") 29 | lang = lang.replace ("\\", "/") 30 | build_path = "build/locale/" + lang + "/LC_MESSAGES/" 31 | target = build_path + "birdfont.mo" 32 | run ("mkdir -p " + build_path); 33 | f_name = f_name.replace ("\\", "/") 34 | run ("msgfmt --output=%s %s" % (target, f_name)); 35 | 36 | -------------------------------------------------------------------------------- /libbirdfont/Allocation.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class WidgetAllocation : GLib.Object { 18 | public int width = 0; 19 | public int height = 0; 20 | public int x = 0; 21 | public int y = 0; 22 | 23 | public WidgetAllocation () { 24 | } 25 | 26 | public WidgetAllocation.for_area (int x, int y, int width, int height) { 27 | this.x = x; 28 | this.y = y; 29 | this.width = width; 30 | this.height = height; 31 | } 32 | 33 | public WidgetAllocation copy () { 34 | WidgetAllocation w = new WidgetAllocation (); 35 | w.x = x; 36 | w.y = y; 37 | w.width = width; 38 | w.height = height; 39 | return w; 40 | } 41 | 42 | public string to_string () { 43 | return @"x: $x, y: $y, width: $width, height: $height\n"; 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /libbirdfont/UniRange.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class UniRange : GLib.Object { 18 | 19 | public unichar start; 20 | public unichar stop; 21 | 22 | public UniRange (unichar start, unichar stop) { 23 | this.start = start; 24 | this.stop = stop; 25 | } 26 | 27 | public unichar length () { 28 | return stop - start + 1; 29 | } 30 | 31 | public bool has_character (unichar c) { 32 | return (start <= c <= stop); 33 | } 34 | 35 | public unichar get_char (unichar index) { 36 | unichar result = start + index; 37 | 38 | if (unlikely (!(start <= result <= stop))) { 39 | warning ("Index out of range in UniRange (%u <= %u <= %u) (index: %u)\n", start, result, stop, index); 40 | } 41 | 42 | return result; 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /libbirdfont/TextListener.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class TextListener : GLib.Object { 18 | 19 | public string label; 20 | public string default_text; 21 | public string button_label; 22 | 23 | public signal void signal_text_input (string text); 24 | public signal void signal_submit (string text); 25 | 26 | private string text; 27 | 28 | public TextListener (string label, string default_text, string button_label) { 29 | this.label = label; 30 | this.default_text = default_text; 31 | this.button_label = button_label; 32 | } 33 | 34 | public void set_text (string t) { 35 | text = t; 36 | signal_text_input (text); 37 | } 38 | 39 | public void submit () { 40 | signal_text_input (text); 41 | signal_submit (text); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/OtfInputStream.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** Reader for otf data types. */ 18 | public class OtfInputStream : Object { 19 | 20 | public FileInputStream fin; 21 | public DataInputStream din; 22 | 23 | public OtfInputStream (FileInputStream i) throws Error { 24 | din = new DataInputStream (i); 25 | fin = i; 26 | } 27 | 28 | public void seek (int64 pos) throws Error 29 | requires (fin.can_seek ()) { 30 | int64 p = fin.tell (); 31 | fin.seek (pos - p, SeekType.CUR); 32 | } 33 | 34 | public uint8 read_byte () throws Error { 35 | return din.read_byte (); 36 | } 37 | 38 | public void close () { 39 | try { 40 | fin.close (); 41 | din.close (); 42 | } catch (GLib.IOError e) { 43 | warning (e.message); 44 | } 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /libbirdfont/Screen.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class Screen { 20 | public static double get_scale () { 21 | return MainWindow.native_window.get_screen_scale (); 22 | } 23 | 24 | public static ImageSurface create_background_surface (int w, int h) { 25 | int width = (int) (get_scale () * w); 26 | int height = (int) (get_scale () * h); 27 | return new ImageSurface(Cairo.Format.ARGB32, width, height); 28 | } 29 | 30 | public static void paint_background_surface(Context cr, Surface s, int x, int y) { 31 | cr.save (); 32 | cr.set_antialias (Cairo.Antialias.NONE); 33 | cr.scale (1 / get_scale (), 1 / get_scale ()); 34 | cr.set_source_surface (s, (int) (x * Screen.get_scale ()), (int) (y * Screen.get_scale ())); 35 | cr.paint (); 36 | cr.restore (); 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/GaspTable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 - 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class GaspTable : OtfTable { 18 | 19 | public const uint16 NONE = 0; 20 | public const uint16 GASP_GRIDFIT = 1; 21 | public const uint16 GASP_DOGRAY = 2; 22 | public const uint16 GASP_SYMMETRIC_GRIDFIT = 4; 23 | public const uint16 GASP_SYMMETRIC_SMOOTHING = 8; 24 | 25 | public GaspTable () { 26 | id = "gasp"; 27 | } 28 | 29 | public override void parse (FontData dis) throws Error { 30 | } 31 | 32 | public void process () throws GLib.Error { 33 | FontData fd = new FontData (); 34 | 35 | fd.add_ushort (0); // version 36 | fd.add_ushort (1); // number of entries 37 | 38 | fd.add_ushort (0xFFFF); // range upper limit 39 | fd.add_ushort (GASP_DOGRAY); // hinting flags 40 | 41 | fd.pad (); 42 | 43 | this.font_data = fd; 44 | } 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /libbirdfont/Headline.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | class Headline : Widget { 21 | 22 | Text label; 23 | 24 | public Headline (string text) { 25 | label = new Text (); 26 | label.set_text (text); 27 | } 28 | 29 | public override void draw (Context cr) { 30 | cr.save (); 31 | Theme.color (cr, "Headline Background"); 32 | cr.rectangle (0, widget_y, allocation.width, 40 * MainWindow.units); 33 | cr.fill (); 34 | cr.restore (); 35 | 36 | cr.save (); 37 | label.set_source_rgba (1, 1, 1, 1); 38 | label.set_font_size (20 * MainWindow.units); 39 | label.draw_at_baseline (cr, 21 * MainWindow.units, widget_y + 25 * MainWindow.units); 40 | cr.restore (); 41 | } 42 | 43 | public override double get_height () { 44 | return 40 * MainWindow.units; 45 | } 46 | 47 | public override double get_width () { 48 | return allocation.width; 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /libbirdfont/OverWriteDialogListener.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class OverWriteDialogListener : GLib.Object { 18 | 19 | public signal void overwrite_signal (); 20 | public signal void cancel_signal (); 21 | 22 | public static bool dont_ask_again = false; 23 | 24 | public string message; 25 | public string overwrite_message; 26 | public string cancel_message; 27 | public string dont_ask_again_message; 28 | 29 | public OverWriteDialogListener () { 30 | message = t_("Overwrite TTF file?"); 31 | overwrite_message = t_("Overwrite"); 32 | cancel_message = t_("Cancel"); 33 | dont_ask_again_message = t_("Yes, don't ask again."); 34 | } 35 | 36 | public void overwrite () { 37 | overwrite_signal (); 38 | } 39 | 40 | public void cancel () { 41 | cancel_signal (); 42 | } 43 | 44 | public void overwrite_dont_ask_again () { 45 | dont_ask_again = true; 46 | overwrite (); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: gcc 3 | sudo: require 4 | dist: xenial 5 | 6 | before_install: 7 | - sudo apt-get update -qq 8 | 9 | install: 10 | - sudo apt-get -y install valac python3-doit libxmlbird-dev libgee-0.8-dev libglib2.0-dev libgtk-3-dev libwebkit2gtk-4.0-dev libnotify-dev libsqlite3-dev 11 | 12 | script: 13 | - ./configure --prefix=/usr 14 | - ./build.py 15 | - ./install.py -d appdir 16 | - wget -c -nv "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" 17 | - chmod a+x linuxdeployqt-continuous-x86_64.AppImage 18 | - ./linuxdeployqt-continuous-x86_64.AppImage --appimage-extract 'usr/bin/patchelf' 19 | - squashfs-root/usr/bin/patchelf --set-rpath '$ORIGIN' appdir/usr/lib/x86_64-linux-gnu/libbirdfont.so.*.* 20 | - ( cd appdir/usr/lib/ ; ln -s x86_64-linux-gnu/lib* . ) 21 | - find appdir/ 22 | - export LD_LIBRARY_PATH=./appdir/usr/lib:./appdir/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH 23 | - |2 24 | ./linuxdeployqt-continuous-x86_64.AppImage appdir/usr/share/applications/*.desktop -appimage \ 25 | -executable=appdir/usr/bin/birdfont-autotrace \ 26 | -executable=appdir/usr/bin/birdfont-export \ 27 | -executable=appdir/usr/bin/birdfont-import 28 | 29 | after_success: 30 | - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh 31 | - bash upload.sh Birdfont*.AppImage* 32 | 33 | branches: 34 | except: 35 | - # Do not build tags that we create when we upload to GitHub Releases 36 | - /^(?i:continuous)/ 37 | -------------------------------------------------------------------------------- /libbirdfont/FileChooser.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class FileChooser : GLib.Object { 18 | 19 | public const uint NONE = 0; 20 | public const uint SAVE = 1; 21 | public const uint LOAD = 1 << 1; 22 | public const uint DIRECTORY = 1 << 2; 23 | 24 | Gee.ArrayList extensions = new Gee.ArrayList (); 25 | 26 | public signal void file_selected (string? path); 27 | 28 | public FileChooser () { 29 | } 30 | 31 | public int extensions_size () { 32 | return extensions.size; 33 | } 34 | 35 | public string get_extension (int i) { 36 | return_val_if_fail (0 <= i < extensions.size, "".dup ()); 37 | return extensions.get (i); 38 | } 39 | 40 | public void add_extension (string file_extension) { 41 | extensions.add (file_extension); 42 | } 43 | 44 | public void selected (string? path) { 45 | file_selected (path); 46 | } 47 | 48 | public void cancel () { 49 | file_selected (null); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /libbirdfont/ToolItem.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class ToolItem : MenuItem { 18 | 19 | public Tool tool; 20 | 21 | public ToolItem (Tool tool) { 22 | base (tool.tip, tool.name); 23 | 24 | this.tool = tool; 25 | 26 | action.connect (() => { 27 | tool.select_action (tool); 28 | }); 29 | } 30 | 31 | public string get_key_binding () { 32 | StringBuilder sb = new StringBuilder (); 33 | 34 | if (key == '\0') { 35 | return "".dup (); 36 | } 37 | 38 | if ((modifiers & CTRL) > 0) { 39 | sb.append ("Ctrl"); 40 | sb.append ("+"); 41 | } 42 | 43 | if ((modifiers & SHIFT) > 0) { 44 | sb.append (t_("Shift")); 45 | sb.append ("+"); 46 | } 47 | 48 | if ((modifiers & ALT) > 0) { 49 | sb.append ("Alt"); 50 | sb.append ("+"); 51 | } 52 | 53 | if ((modifiers & LOGO) > 0) { 54 | sb.append ("Super"); 55 | sb.append ("+"); 56 | } 57 | 58 | sb.append_unichar (key); 59 | 60 | return sb.str; 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /libbirdfont/StrokeTask.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class StrokeTask : Task { 18 | Path original; // path in gui thread 19 | Path background_path; // path in background thread 20 | 21 | public StrokeTask (Path path) { 22 | base (null, true); 23 | original = path; 24 | background_path = path.copy (); 25 | } 26 | 27 | public StrokeTask.none () { 28 | base (null, true); 29 | original = new Path (); 30 | background_path = new Path (); 31 | } 32 | 33 | public override void run () { 34 | PathList stroke; 35 | double w; 36 | StrokeTool tool = new StrokeTool.with_task (this); 37 | 38 | w = background_path.stroke; 39 | 40 | stroke = tool.get_stroke (background_path, w); 41 | 42 | IdleSource idle = new IdleSource (); 43 | idle.set_callback (() => { 44 | if (!is_cancelled ()) { 45 | original.full_stroke = stroke; 46 | GlyphCanvas.redraw (); 47 | } 48 | 49 | return false; 50 | }); 51 | idle.attach (null); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /libbirdfont/Tab.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class Tab : GLib.Object { 18 | 19 | bool always_open; 20 | double width; 21 | string label; 22 | FontDisplay display; 23 | GlyphCollection glyph_collection; 24 | 25 | public Tab (FontDisplay glyph, double tab_width, bool always_open) { 26 | width = tab_width; 27 | display = glyph; 28 | this.always_open = always_open; 29 | label = display.get_label (); 30 | glyph_collection = new GlyphCollection.with_glyph ('\0', ""); 31 | } 32 | 33 | public bool has_close_button () { 34 | return !always_open; 35 | } 36 | 37 | public GlyphCollection get_glyph_collection () { 38 | return glyph_collection; 39 | } 40 | 41 | public void set_glyph_collection (GlyphCollection gc) { 42 | glyph_collection = gc; 43 | } 44 | 45 | public void set_display (FontDisplay fd) { 46 | display = fd; 47 | } 48 | 49 | public FontDisplay get_display () { 50 | return display; 51 | } 52 | 53 | public double get_width () { 54 | return width; 55 | } 56 | 57 | public string get_label () { 58 | return label; 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libbirdfont/ThemeTools.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class ThemeTools : ToolCollection { 21 | public static Gee.ArrayList expanders; 22 | public static ColorPicker color_picker; 23 | 24 | public ThemeTools () { 25 | expanders = new Gee.ArrayList (); 26 | 27 | Expander font_name = new Expander (); 28 | font_name.add_tool (new FontName ()); 29 | 30 | Expander color_tools = new Expander (t_("Color")); 31 | color_picker = new ColorPicker (); 32 | 33 | color_picker.fill_color_updated.connect (() => { 34 | Color c = color_picker.get_fill_color (); 35 | ThemeTab.get_instance ().color_updated (c); 36 | }); 37 | 38 | color_tools.add_tool (color_picker); 39 | 40 | expanders.add (font_name); 41 | expanders.add (color_tools); 42 | } 43 | 44 | public override Gee.ArrayList get_displays () { 45 | Gee.ArrayList d = new Gee.ArrayList (); 46 | return d; 47 | } 48 | 49 | public override Gee.ArrayList get_expanders () { 50 | return expanders; 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/Alternate.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class Alternate : GLib.Object { 18 | 19 | public string glyph_name; 20 | public Gee.ArrayList alternates; 21 | public string tag; 22 | 23 | public Alternate (string glyph_name, string tag) { 24 | this.glyph_name = glyph_name; 25 | this.alternates = new Gee.ArrayList (); 26 | this.tag = tag; 27 | } 28 | 29 | public bool is_empty () { 30 | return alternates.size == 0; 31 | } 32 | 33 | public void add (string alternate_name) { 34 | alternates.add (alternate_name); 35 | } 36 | 37 | public void remove_alternate (string alt) { 38 | int i = 0; 39 | foreach (string a in alternates) { 40 | if (a == alt) { 41 | break; 42 | } 43 | i++; 44 | } 45 | 46 | if (i < alternates.size) { 47 | alternates.remove_at (i); 48 | } 49 | } 50 | 51 | public void remove (GlyphCollection g) { 52 | remove_alternate (g.get_name ()); 53 | } 54 | 55 | public Alternate copy () { 56 | Alternate n = new Alternate (glyph_name, tag); 57 | 58 | foreach (string s in alternates) { 59 | n.add (s); 60 | } 61 | 62 | return n; 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /libbirdfont/ExportCallback.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class ExportCallback : GLib.Object { 18 | 19 | public signal void file_exported (); 20 | public bool preview = false; 21 | 22 | public ExportCallback () { 23 | } 24 | 25 | public void export_fonts_in_background () { 26 | Font font = BirdFont.get_current_font (); 27 | 28 | if (!MainWindow.native_window.can_export ()) { 29 | return; 30 | } 31 | 32 | if (font.font_file == null) { 33 | MenuTab.set_save_callback (new SaveCallback ()); 34 | MenuTab.save_callback.file_saved.connect (() => { 35 | MainWindow.native_window.export_font (); 36 | }); 37 | MenuTab.save_callback.save (); 38 | } else { 39 | MainWindow.native_window.export_font (); 40 | } 41 | } 42 | 43 | /** Export TTF, EOT and SVG fonts. */ 44 | public static void export_fonts () { 45 | Font font = BirdFont.get_current_font (); 46 | 47 | if (ExportSettings.export_ttf_setting (font) || ExportSettings.export_eot_setting (font)) { 48 | ExportTool.export_ttf_font (); 49 | } 50 | 51 | if (ExportSettings.export_svg_setting (font)) { 52 | ExportTool.export_svg_font (); 53 | } 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /libbirdfont/GlyphSelection.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** A tab for picking characters in the font. */ 18 | public class GlyphSelection : OverView { 19 | 20 | public signal void selected_glyph (GlyphCollection gc); 21 | 22 | public GlyphSelection () { 23 | base (null, false, false); 24 | update_default_characterset (); 25 | 26 | OverviewTools.update_overview_characterset (this); 27 | FontDisplay.dirty_scrollbar = true; 28 | 29 | open_glyph_signal.connect ((gc) => { 30 | selected_glyph (gc); 31 | Toolbox.redraw_tool_box (); 32 | }); 33 | 34 | Toolbox.set_toolbox_from_tab (get_name ()); 35 | 36 | IdleSource idle = new IdleSource (); 37 | 38 | idle.set_callback (() => { 39 | update_default_characterset (); 40 | return false; 41 | }); 42 | 43 | idle.attach (null); 44 | } 45 | 46 | void update_default_characterset () { 47 | if (BirdFont.get_current_font ().length () > 0) { 48 | display_all_available_glyphs (); 49 | } else { 50 | GlyphRange gr = new GlyphRange (); 51 | DefaultCharacterSet.use_default_range (gr); 52 | set_current_glyph_range (gr); 53 | } 54 | 55 | update_item_list (); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/ContextualLigatureCollection.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Math; 15 | 16 | namespace BirdFont { 17 | 18 | public class ContextualLigatureCollection : GLib.Object { 19 | 20 | public Gee.ArrayList ligature_context; 21 | public Gee.ArrayList ligatures; 22 | 23 | public ContextualLigatureCollection (GlyfTable glyf_table) { 24 | ligature_context = new Gee.ArrayList (); 25 | ligatures = new Gee.ArrayList (); 26 | add_contextual_ligatures (glyf_table); 27 | } 28 | 29 | public int16 get_size () { 30 | if (ligatures.size != ligature_context.size) { 31 | warning ("Expecting one substitution table per contextual ligature"); 32 | } 33 | 34 | return (int16) ligature_context.size; 35 | } 36 | 37 | public bool has_ligatures () { 38 | return ligature_context.size > 0; 39 | } 40 | 41 | void add_contextual_ligatures (GlyfTable glyf_table) { 42 | Font font = BirdFont.get_current_font (); 43 | 44 | foreach (ContextualLigature c in font.ligature_substitution.contextual_ligatures) { 45 | ligature_context.add (c); 46 | ligatures.add (new LigatureCollection.contextual (glyf_table, c)); 47 | } 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /libbirdfont/GuideTab.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Cairo; 15 | using Math; 16 | 17 | namespace BirdFont { 18 | 19 | public class GuideTab : Table { 20 | 21 | Gee.ArrayList rows = new Gee.ArrayList (); 22 | 23 | public GuideTab () { 24 | } 25 | 26 | public override Gee.ArrayList get_rows () { 27 | return rows; 28 | } 29 | 30 | public override void selected_row (Row row, int column, bool delete_button) { 31 | Font font = BirdFont.get_current_font (); 32 | int index = row.get_index (); 33 | 34 | if (delete_button) { 35 | return_if_fail (0 <= index < font.custom_guides.size); 36 | BirdFont.get_current_font ().custom_guides.remove_at (index); 37 | update_rows (); 38 | } 39 | } 40 | 41 | public override void update_rows () { 42 | int i = 0; 43 | 44 | rows.clear (); 45 | 46 | rows.add (new Row.headline (t_("Guides"))); 47 | 48 | foreach (Line guide in BirdFont.get_current_font ().custom_guides) { 49 | rows.add (new Row.columns_1 (guide.label, i)); 50 | i++; 51 | } 52 | 53 | GlyphCanvas.redraw (); 54 | } 55 | 56 | public override string get_label () { 57 | return t_("Guides"); 58 | } 59 | 60 | public override string get_name () { 61 | return "Guides"; 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /libbirdfont/ToolCollection.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public abstract class ToolCollection : GLib.Object { 21 | public double scroll = 0; 22 | public double content_height = 0; 23 | private Tool current_tool = new Tool ("no_icon"); 24 | 25 | public abstract Gee.ArrayList get_expanders (); 26 | 27 | public virtual Gee.ArrayList get_displays () { 28 | return new Gee.ArrayList (); 29 | } 30 | 31 | public void set_current_tool (Tool tool) { 32 | current_tool = tool; 33 | } 34 | 35 | public Tool get_current_tool () { 36 | return current_tool; 37 | } 38 | 39 | public void cache () { 40 | foreach (Expander e in get_expanders ()) { 41 | e.cache (); 42 | } 43 | } 44 | 45 | public void clear_cache () { 46 | foreach (Expander e in get_expanders ()) { 47 | e.clear_cache (); 48 | } 49 | } 50 | 51 | public void redraw () { 52 | foreach (Expander e in get_expanders ()) { 53 | e.redraw (); 54 | } 55 | } 56 | 57 | public virtual void selected () { 58 | reset_selection (current_tool); 59 | current_tool.set_selected (true); 60 | } 61 | 62 | public virtual void reset_selection (Tool current_tool) { 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /libbirdfont/Test.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class Test : Object { 18 | public Callback callback; 19 | public string name; 20 | double time_stamp; 21 | bool benchmark = false; 22 | 23 | public Test.time (string name) { 24 | this.name = name; 25 | benchmark = true; 26 | timer_start (); 27 | } 28 | 29 | public Test (Callback callback, string name, bool benchmark = false) { 30 | this.callback = callback; 31 | this.name = name; 32 | this.time_stamp = 0; 33 | this.benchmark = benchmark; 34 | } 35 | 36 | public void timer_start () { 37 | time_stamp = GLib.get_real_time (); 38 | } 39 | 40 | public double get_time () { 41 | double stop_time = GLib.get_real_time (); 42 | 43 | if (time_stamp == 0) { 44 | return 0; 45 | } 46 | 47 | return (stop_time - time_stamp) / 1000000.0; 48 | } 49 | 50 | public bool is_benchmark () { 51 | return benchmark; 52 | } 53 | 54 | public void print () { 55 | stdout.printf (get_test_time ()); 56 | } 57 | 58 | public string get_test_time () { 59 | double stop_time = GLib.get_real_time (); 60 | 61 | if (time_stamp == 0) { 62 | return ""; 63 | } 64 | 65 | return @"$name $((stop_time - time_stamp) / 1000000.0)s\n"; 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/KerningPair.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using B; 17 | 18 | namespace BirdFont { 19 | 20 | /** A list of all kerning pairs for one glyph. */ 21 | public class KerningPair : GLib.Object { 22 | public Glyph character; 23 | public Gee.ArrayList kerning; 24 | public Gee.ArrayList right; 25 | 26 | public KerningPair (Glyph left) { 27 | character = left; 28 | right = new Gee.ArrayList (); 29 | kerning = new Gee.ArrayList (); 30 | } 31 | 32 | public void add_unique (Glyph g, double k) { 33 | if (!right.contains ((!) g)) { 34 | right.add ((!) g); 35 | kerning.add (new Kerning.for_glyph (g, k)); 36 | } 37 | } 38 | 39 | public void sort () { 40 | kerning.sort ((a, b) => { 41 | Kerning first, next; 42 | first = (Kerning) a; 43 | next = (Kerning) b; 44 | return strcmp (((!)first.glyph).get_unichar_string (), ((!)next.glyph).get_unichar_string ()); 45 | }); 46 | } 47 | 48 | public void print () { 49 | if (kerning.size == 0) { 50 | warning ("No pairs."); 51 | } 52 | 53 | foreach (Kerning k in kerning) { 54 | if (k.glyph != null) { 55 | stdout.printf (@"$(character.get_name ()) <-> $(((!) k.glyph).get_name ()): $(k.val)\n"); 56 | } 57 | } 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/CmapSubtableFormat0.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** Format 0 cmap subtable */ 18 | public class CmapSubtableFormat0 : CmapSubtable { 19 | FontData cmap_data = new FontData (); 20 | 21 | public CmapSubtableFormat0 () { 22 | } 23 | 24 | public override ushort get_platform () { 25 | return 1; 26 | } 27 | 28 | public override ushort get_encoding () { 29 | return 0; 30 | } 31 | 32 | public override FontData get_cmap_data () { 33 | return cmap_data; 34 | } 35 | 36 | public override void generate_cmap_data (GlyfTable glyf_table) 37 | throws GLib.Error { 38 | FontData fd = new FontData (); 39 | 40 | fd.add_u16 (0); // Format 41 | fd.add_u16 (262); // Length 42 | fd.add_u16 (0); // Language 43 | 44 | for (uint i = 0; i < 256; i++) { 45 | fd.add (get_gid_for_unichar ((unichar) i, glyf_table)); 46 | } 47 | 48 | cmap_data = fd; 49 | } 50 | 51 | uint8 get_gid_for_unichar (unichar c, GlyfTable glyf_table) { 52 | uint32 index = 0; 53 | foreach (GlyphCollection g in glyf_table.glyphs) { 54 | if (g.get_unicode_character () == c && !g.is_unassigned ()) { 55 | return (index <= uint8.MAX) ? (uint8) index : 0; 56 | } 57 | index++; 58 | } 59 | return 0; 60 | } 61 | } 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /libbirdfont/PointSelection.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Math; 16 | using Cairo; 17 | 18 | namespace BirdFont { 19 | 20 | /** One selected point and its path. */ 21 | public class PointSelection : GLib.Object { 22 | 23 | public EditPointHandle handle; 24 | public EditPoint point; 25 | public Path path; 26 | 27 | public PointSelection (EditPoint ep, Path p) { 28 | path = p; 29 | point = ep; 30 | handle = new EditPointHandle.empty (); 31 | } 32 | 33 | public PointSelection.handle_selection (EditPointHandle h, Path p) { 34 | path = p; 35 | point = new EditPoint (); 36 | handle = h; 37 | } 38 | 39 | public PointSelection.empty () { 40 | path = new Path (); 41 | point = new EditPoint (); 42 | handle = new EditPointHandle.empty (); 43 | } 44 | 45 | /** @return true if this point is the first point in the path. */ 46 | public bool is_first () { 47 | return_val_if_fail (path.points.size > 0, false); 48 | return path.points.get (0) == point; 49 | } 50 | 51 | /** @return true if this point is the last point in the path. */ 52 | public bool is_last () { 53 | return_val_if_fail (path.points.size > 0, false); 54 | return path.points.get (path.points.size - 1) == point; 55 | } 56 | 57 | public bool is_endpoint () { 58 | return is_first () || is_last (); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libbirdfont/FontName.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class FontName : Tool { 20 | 21 | public FontName (string? name = null, string tip = "") { 22 | base (null , tip); 23 | 24 | if (name != null) { 25 | base.name = (!) name; 26 | } 27 | 28 | select_action.connect ((tool) => { 29 | MenuTab.select_overview (); 30 | }); 31 | } 32 | 33 | public override void draw_tool (Context cr, double px, double py) { 34 | Text font_name; 35 | double text_height; 36 | double extent; 37 | double width = Toolbox.allocation_width * Toolbox.get_scale (); 38 | double max_width; 39 | double x = this.x - px; 40 | double y = this.y - py; 41 | 42 | cr.save (); 43 | // tab label 44 | font_name = new Text (); 45 | font_name.set_text (BirdFont.get_current_font ().get_full_name ()); 46 | text_height = 22 * Toolbox.get_scale (); 47 | 48 | max_width = (width - 2 * x * Toolbox.get_scale ()); 49 | font_name.set_font_size (text_height); 50 | extent = font_name.get_extent () * Toolbox.get_scale (); 51 | if (extent > max_width) { 52 | text_height *= max_width / extent; 53 | } 54 | 55 | Theme.text_color (font_name, "Font Name"); 56 | font_name.set_font_size (text_height); 57 | font_name.draw_at_top (cr, x, y); 58 | cr.restore (); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libbirdfont/MenuAction.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class MenuAction : GLib.Object { 20 | public string label; 21 | public signal void action (MenuAction a); 22 | public int index = -1; 23 | public bool has_delete_button = true; 24 | public double width = 100; 25 | public Text text; 26 | 27 | bool selected = false; 28 | 29 | public MenuAction (string label) { 30 | this.label = label; 31 | } 32 | 33 | public void set_selected (bool s) { 34 | selected = s; 35 | } 36 | 37 | public virtual void draw (double x, double y, Context cr) { 38 | if (selected) { 39 | cr.save (); 40 | Theme.color (cr, "Highlighted 1"); 41 | cr.rectangle (x - 2, y - 12, width, 15); 42 | cr.fill_preserve (); 43 | cr.stroke (); 44 | cr.restore (); 45 | } 46 | 47 | if (has_delete_button) { 48 | cr.save (); 49 | Theme.color (cr, "Foreground 1"); 50 | cr.move_to (x + width - 10, y - 2); 51 | cr.line_to (x + width - 10 - 5, y - 2 - 5); 52 | cr.move_to (x + width - 10 - 5, y - 2); 53 | cr.line_to (x + width - 10, y - 2 - 5); 54 | cr.set_line_width (1); 55 | cr.stroke (); 56 | cr.restore (); 57 | } 58 | 59 | text = new Text (label); 60 | Theme.text_color (text, "Foreground 1"); 61 | text.draw_at_baseline (cr, x, y); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /libbirdfont/Task.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 2015 2019 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class Task : GLib.Object { 18 | 19 | public delegate void Runnable (); 20 | public signal void done (); 21 | Runnable task; 22 | bool cancelled = false; 23 | bool cancelable = false; 24 | 25 | public Task.empty () { 26 | } 27 | 28 | public Task (owned Runnable? r, bool cancelable = false) { 29 | if (r != null) { 30 | task = (!) ((owned) r); 31 | } 32 | 33 | this.cancelable = cancelable; 34 | } 35 | 36 | public bool is_cancellable () { 37 | bool c; 38 | 39 | lock (cancelled) { 40 | c = cancelable; 41 | } 42 | 43 | return c; 44 | } 45 | 46 | public void cancel () { 47 | lock (cancelled) { 48 | if (unlikely (!cancelable)) { 49 | warning ("Task is not cancelable."); 50 | } 51 | 52 | cancelled = true; 53 | } 54 | } 55 | 56 | public bool is_cancelled () { 57 | bool c; 58 | 59 | lock (cancelled) { 60 | c = cancelled; 61 | } 62 | 63 | return c; 64 | } 65 | 66 | public virtual void run () { 67 | task (); 68 | 69 | IdleSource idle = new IdleSource (); 70 | idle.set_callback (() => { 71 | done (); 72 | return false; 73 | }); 74 | idle.attach (null); 75 | } 76 | 77 | public void* perform_task() { 78 | run (); 79 | return null; 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /libbirdfont/GlyphTable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Gee; 16 | 17 | namespace BirdFont { 18 | 19 | /** A sorted table of glyphs with search index. */ 20 | public class GlyphTable : GLib.Object { 21 | 22 | TreeMap map; 23 | 24 | public GlyphTable () { 25 | map = new TreeMap (); 26 | } 27 | 28 | public void remove_all () { 29 | map.clear (); 30 | } 31 | 32 | public void @for_each (Func func) { 33 | if (unlikely (is_null (map))) { 34 | warning ("No data in table"); 35 | return; 36 | } 37 | 38 | foreach (var entry in map.entries) { 39 | func (entry.value); 40 | } 41 | } 42 | 43 | public bool has_key (string n) { 44 | return map.has_key (n); 45 | } 46 | 47 | public void remove (string name) { 48 | map.unset (name); 49 | } 50 | 51 | public uint length () { 52 | return map.size; 53 | } 54 | 55 | public new GlyphCollection? @get (string name) { 56 | return map.get (name); 57 | } 58 | 59 | public new GlyphCollection? nth (uint index) { 60 | uint i = 0; 61 | 62 | foreach (var k in map.keys) { 63 | if (i == index) { 64 | return map.get (k); 65 | } 66 | i++; 67 | } 68 | 69 | return null; 70 | } 71 | 72 | public bool insert (string key, GlyphCollection g) { 73 | map.set (key, g); 74 | return true; 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Birdfont logo][birdfont] 2 | 3 | # Birdfont - Font Editor 4 | 5 | Birdfont is a font editor which can create vector graphics and 6 | export SVG, EOT and TTF fonts. 7 | 8 | Author: Johan Mattsson and others see AUTHORS for full attribution. 9 | License: GNU GPL v3 10 | Webpage: https://birdfont.org 11 | Bugtracker: https://birdfont.org/bugtracker/my_view_page.php 12 | 13 | ## Building from Source 14 | 15 | Install vala and all required libraries, they are most likely in 16 | packages with a -dev or -devel affix: 17 | 18 | valac 19 | python3-doit 20 | libxmlbird-dev 21 | libgee-0.8-dev 22 | libglib2.0-dev 23 | libgtk-3-dev 24 | libwebkit2gtk-4.0-dev 25 | libnotify-dev 26 | libsqlite3-dev 27 | 28 | XML Bird is available from [birdfont.org][xmlbird]. 29 | 30 | BirdFont have two build systems, one python script that builds all 31 | binaries at once and one dependency based build system that uses 32 | doit. 33 | 34 | Configure, build and install with python: 35 | 36 | ./configure 37 | ./build.py 38 | sudo ./install.py 39 | 40 | Configure, build and install with doit: 41 | 42 | ./configure 43 | doit3 44 | sudo ./install.py 45 | 46 | The default prefix is /usr/local on Fedora should BirdFont be compiled with 47 | /usr as prefix. 48 | 49 | ./configure --prefix=/usr 50 | ./build.py 51 | sudo ./install.py 52 | 53 | All patches must be compiled with support for valas null pointer checks. 54 | Configure the project with ./configure --nonnull 55 | 56 | ## Packages 57 | 58 | Windows and Mac binaries can be downloaded from 59 | https://birdfont.org Many Linux distributions have packages of 60 | Birdfont in their repositories. There is a BSD package in OpenBSD. 61 | 62 | [birdfont]: https://birdfont.org/images/birdfont_logo2.png "Birdfont logo" 63 | [xmlbird]: https://birdfont.org/xmlbird.php "XML Bird – XML Parser for programs written in VALA" 64 | 65 | -------------------------------------------------------------------------------- /libbirdfont/OtfLabel.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** Gsub substitutions will be performed kening and spacing tab when 18 | * this tool is selected. 19 | */ 20 | public class OtfLabel : LabelTool { 21 | 22 | public bool active_substitution = false; 23 | public string tag; 24 | 25 | public signal void otf_feature_activity (bool enable, string tag); 26 | 27 | public OtfLabel (string tag) { 28 | string label = get_string(tag); 29 | base (label); 30 | 31 | this.tag = tag; 32 | 33 | select_action.connect ((self) => { 34 | active_substitution = !active_substitution; 35 | set_selected_tag (active_substitution); 36 | }); 37 | } 38 | 39 | public void set_selected_tag (bool enabled) { 40 | set_selected (enabled); 41 | otf_feature_activity (enabled, tag); 42 | } 43 | 44 | /** @return translated string representation of an OTF feature tag. */ 45 | public static string get_string (string tag) { 46 | if (tag == "salt") { 47 | return t_("Stylistic Alternate") + " (salt)"; 48 | } else if (tag == "smcp") { 49 | return t_("Small Caps") + " (smcp)"; 50 | } else if (tag == "c2sc") { 51 | return t_("Capitals to Small Caps") + " (c2sc)"; 52 | } else if (tag == "swsh") { 53 | return t_("Swashes") + " (swsh)"; 54 | } 55 | 56 | warning (@"Unknown tag: $tag"); 57 | return tag; 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /libbirdfont/PathList.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class PathList : GLib.Object { 18 | public Gee.ArrayList paths; 19 | 20 | public PathList () { 21 | paths = new Gee.ArrayList (); 22 | } 23 | 24 | public PathList.for_path (Path p) { 25 | paths = new Gee.ArrayList (); 26 | paths.add (p); 27 | } 28 | 29 | public void remove (Path p) { 30 | paths.remove (p); 31 | } 32 | 33 | public void add_unique (Path p) { 34 | if (paths.index_of (p) == -1) { 35 | paths.add (p); 36 | } 37 | } 38 | 39 | public void add (Path p) { 40 | paths.add (p); 41 | } 42 | 43 | public void append (PathList pl) { 44 | foreach (Path p in pl.paths) { 45 | paths.add (p); 46 | } 47 | } 48 | 49 | public void clear () { 50 | paths.clear (); 51 | } 52 | 53 | public Path get_first_path () { 54 | if (unlikely (paths.size == 0)) { 55 | warning ("No path"); 56 | return new Path (); 57 | } 58 | 59 | return paths.get (0); 60 | } 61 | 62 | public Path merge_all () { 63 | Path p = get_first_path (); 64 | 65 | for (int i = 1; i < paths.size; i++) { 66 | p.append_path (paths.get (i)); 67 | } 68 | 69 | return p; 70 | } 71 | 72 | public PathList copy () { 73 | PathList pl = new PathList (); 74 | 75 | foreach (Path p in paths) { 76 | pl.add (p.copy ()); 77 | } 78 | 79 | return pl; 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /libbirdfont/SpacingClass.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Cairo; 15 | using Math; 16 | 17 | namespace BirdFont { 18 | 19 | public class SpacingClass : GLib.Object { 20 | 21 | public string first; 22 | public string next; 23 | 24 | bool update_first = true; 25 | TextListener listener; 26 | 27 | public signal void updated (SpacingClass s); 28 | 29 | public SpacingClass (string first, string next) { 30 | this.first = first; 31 | this.next = next; 32 | } 33 | 34 | public void set_first () { 35 | update_first = true; 36 | update (first); 37 | } 38 | 39 | public void set_next () { 40 | update_first = false; 41 | update (next); 42 | } 43 | 44 | public void update_class (string value, bool first) { 45 | update_first = first; 46 | update (value); 47 | } 48 | 49 | void update (string val) { 50 | listener = new TextListener (t_("Character"), val, t_("Set")); 51 | 52 | listener.signal_text_input.connect ((text) => { 53 | string v = text; 54 | 55 | if (v.has_prefix ("U+") || v.has_prefix ("u+")) { 56 | v = ((!) Font.to_unichar (v).to_string ()).dup (); 57 | } 58 | 59 | if (update_first) { 60 | first = v.dup (); 61 | } else { 62 | next = v.dup (); 63 | } 64 | }); 65 | 66 | listener.signal_submit.connect (() => { 67 | TabContent.hide_text_input (); 68 | updated (this); 69 | }); 70 | 71 | TabContent.show_text_input (listener); 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /libbirdfont/Button.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class Button : Widget { 20 | 21 | Text label; 22 | double padding; 23 | double font_size; 24 | 25 | public signal void action (); 26 | 27 | public Button (string label, double margin_bottom = 0) { 28 | this.margin_bottom = margin_bottom; 29 | font_size = 17 * MainWindow.units; 30 | this.label = new Text (label, font_size); 31 | padding = 15 * MainWindow.units; 32 | } 33 | 34 | public override void draw (Context cr) { 35 | cr.save (); 36 | Theme.color (cr, "Button Background 3"); 37 | draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding); 38 | cr.fill (); 39 | cr.restore (); 40 | 41 | cr.save (); 42 | Theme.color (cr, "Button Border 3"); 43 | cr.set_line_width (1); 44 | draw_rounded_rectangle (cr, widget_x, widget_y, get_width (), padding, padding); 45 | cr.stroke (); 46 | cr.restore (); 47 | 48 | cr.save (); 49 | Theme.text_color (label, "Button Foreground"); 50 | label.draw_at_top (cr, widget_x + padding, widget_y + (2 * padding - font_size - 3 * MainWindow.units) / 2.0); 51 | cr.restore (); 52 | } 53 | 54 | public override double get_height () { 55 | return 2 * padding; 56 | } 57 | 58 | public override double get_width () { 59 | return label.get_width () + 2 * padding; 60 | } 61 | 62 | public override void button_release (uint button, double x, double y) { 63 | if (is_over (x, y)) { 64 | action (); 65 | } 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /libbirdfont/Renderer/FontCache.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Gee; 16 | 17 | namespace BirdFont { 18 | 19 | /** Thread specific font cache. */ 20 | public class FontCache { 21 | public static FallbackFont fallback_font; 22 | 23 | static FontCache? default_cache = null; 24 | Gee.HashMap fonts; 25 | CachedFont fallback; 26 | 27 | public FontCache () { 28 | if (is_null (fallback_font)) { 29 | fallback_font = new FallbackFont (); 30 | } 31 | 32 | fallback = new CachedFont (null); 33 | fonts = new Gee.HashMap (); 34 | } 35 | 36 | public CachedFont get_font (string file_name) { 37 | CachedFont c; 38 | Font f; 39 | bool ok; 40 | 41 | if (file_name == "") { 42 | return fallback; 43 | } 44 | 45 | if (fonts.has_key (file_name)) { 46 | c = fonts.get (file_name); 47 | return c; 48 | } 49 | 50 | f = new Font (); 51 | f.set_file (file_name); 52 | ok = f.load (); 53 | if (!ok) { 54 | stderr.printf ("Can't load %s\n", file_name); 55 | return new CachedFont (null); 56 | } 57 | 58 | c = new CachedFont (f); 59 | 60 | if (file_name == "") { 61 | warning ("No file."); 62 | return c; 63 | } 64 | 65 | fonts.set (file_name, c); 66 | return c; 67 | } 68 | 69 | public static FontCache get_default_cache () { 70 | if (default_cache == null) { 71 | default_cache = new FontCache (); 72 | } 73 | 74 | return (!) default_cache; 75 | } 76 | 77 | public CachedFont get_fallback () { 78 | return fallback; 79 | } 80 | 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /libbirdfont/BackgroundTab.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Math; 16 | using Cairo; 17 | 18 | namespace BirdFont { 19 | 20 | public class BackgroundTab : Glyph { 21 | 22 | static BackgroundTab singleton; 23 | 24 | public BackgroundTab () { 25 | base ("", '\0'); 26 | singleton = this; 27 | 28 | Toolbox tools = MainWindow.get_toolbox (); 29 | ZoomTool z = (ZoomTool) tools.get_tool ("zoom_tool"); 30 | z.store_current_view (); 31 | 32 | layers.add_layer (new Layer ()); 33 | } 34 | 35 | public static BackgroundTab get_instance () { 36 | if (is_null (singleton)) { 37 | singleton = new BackgroundTab (); 38 | } 39 | return singleton; 40 | } 41 | 42 | public override string get_name () { 43 | return "Backgrounds"; 44 | } 45 | 46 | public override string get_label () { 47 | return t_("Background Image"); 48 | } 49 | 50 | public override void selected_canvas () { 51 | base.selected_canvas (); 52 | 53 | GlyphCanvas canvas = MainWindow.get_glyph_canvas (); 54 | GlyphCollection gc = new GlyphCollection ('\0', ""); 55 | 56 | GlyphMaster master = new GlyphMaster (); 57 | master.add_glyph (this); 58 | gc.add_master (master); 59 | 60 | canvas.set_current_glyph_collection (gc, false); 61 | DrawingTools.background_scale.set_tool_visibility (true); 62 | ZoomTool.zoom_full_background_image (); 63 | } 64 | 65 | public override void draw (WidgetAllocation allocation, Context cr) { 66 | base.draw (allocation, cr); 67 | Tool t = Toolbox.background_tools.select_background; 68 | t.draw_action (t, cr, this); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/FeatureList.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class FeatureList : GLib.Object { 18 | 19 | public Gee.ArrayList features = new Gee.ArrayList (); 20 | 21 | public FeatureList () { 22 | } 23 | 24 | public void add (Feature f) { 25 | features.add (f); 26 | } 27 | 28 | public FontData generate_feature_tags () throws GLib.Error { 29 | FontData fd = new FontData (); 30 | 31 | features.sort ((fa, fb) => { 32 | Feature a = (Feature) fa; 33 | Feature b = (Feature) fb; 34 | return strcmp (a.tag, b.tag); 35 | }); 36 | 37 | fd.add_ushort ((uint16) features.size); // number of features 38 | 39 | uint offset = 2 + 6 * features.size; 40 | foreach (Feature feature in features) { 41 | // feature tag: aalt, clig etc. 42 | fd.add_tag (feature.tag); 43 | 44 | // offset to feature from beginning of this table 45 | fd.add_ushort ((uint16) offset); 46 | 47 | offset += 4 + 2 * feature.get_public_lookups (); 48 | 49 | if (feature.get_public_lookups () == 0) { 50 | warning (@"No lookups for $(feature.tag)"); 51 | } 52 | } 53 | 54 | foreach (Feature feature in features) { 55 | // feature prameters (null) 56 | fd.add_ushort (0); 57 | 58 | // number of lookups 59 | fd.add_ushort ((uint16) feature.public_lookups.size); 60 | 61 | foreach (string p in feature.public_lookups) { 62 | // reference to a lookup table (lookup index) 63 | fd.add_ushort (feature.lookups.find (p)); 64 | } 65 | } 66 | 67 | return fd; 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /libbirdfont/SpacingClassTools.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class SpacingClassTools : ToolCollection { 21 | public static Gee.ArrayList expanders; 22 | 23 | public SpacingClassTools () { 24 | expanders = new Gee.ArrayList (); 25 | 26 | Expander font_name = new Expander (); 27 | font_name.add_tool (new FontName ()); 28 | 29 | Expander spacing_class_tools = new Expander (); 30 | Tool insert = new Tool ("insert_glyph_from_overview_in_spacing_class", t_("Insert glyph from overview")); 31 | 32 | insert.set_icon ("insert_glyph_from_overview"); 33 | 34 | insert.select_action.connect ((self) => { 35 | GlyphSelection glyph_selection = new GlyphSelection (); 36 | 37 | glyph_selection.selected_glyph.connect ((glyph_collection) => { 38 | SpacingClassTab.set_class (glyph_collection.get_name ()); 39 | MainWindow.get_tab_bar ().select_tab_name ("SpacingClasses"); 40 | }); 41 | 42 | GlyphCanvas.set_display (glyph_selection); 43 | self.set_selected (false); 44 | 45 | TabContent.hide_text_input (); 46 | }); 47 | spacing_class_tools.add_tool (insert); 48 | 49 | expanders.add (font_name); 50 | 51 | expanders.add (spacing_class_tools); 52 | } 53 | 54 | public override Gee.ArrayList get_expanders () { 55 | return expanders; 56 | } 57 | 58 | public override Gee.ArrayList get_displays () { 59 | Gee.ArrayList d = new Gee.ArrayList (); 60 | d.add ("SpacingClasses"); 61 | return d; 62 | } 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /libbirdfont/CharacterInfo.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | /** Display functions for a unicode character database entry. */ 20 | public class CharacterInfo : GLib.Object { 21 | 22 | public unichar unicode; 23 | 24 | private static Text? info_icon = null; 25 | Text icon; 26 | double x = 0; 27 | double y = 0; 28 | bool ligature = false; 29 | string name = ""; 30 | 31 | public CharacterInfo (unichar c, GlyphCollection? gc) { 32 | unicode = c; 33 | 34 | if (info_icon == null) { 35 | info_icon= new Text ("info_icon", 22); 36 | ((!) info_icon).load_font ("icons.birdfont"); 37 | } 38 | 39 | icon = (!) info_icon; 40 | 41 | if (gc != null) { 42 | ligature = ((!) gc).is_unassigned (); 43 | name = ((!) gc).get_name (); 44 | } 45 | } 46 | 47 | public string get_name () { 48 | return name; 49 | } 50 | 51 | public bool is_ligature () { 52 | return ligature; 53 | } 54 | 55 | public string get_entry () { 56 | return CharDatabase.get_unicode_database_entry (unicode); 57 | } 58 | 59 | public void set_position (double x, double y) { 60 | this.x = x; 61 | this.y = y; 62 | } 63 | 64 | public bool is_over_icon (double px, double py) { 65 | return (x <= px <= x + 12) && (y <= py <= y + 24); 66 | } 67 | 68 | public void draw_icon (Context cr, bool selected, double px, double py) { 69 | if (selected) { 70 | Theme.text_color (icon, "Overview Selected Foreground"); 71 | } else { 72 | Theme.text_color (icon, "Overview Foreground"); 73 | } 74 | 75 | icon.draw_at_top (cr, px, py); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /libbirdfont/ScaledBackgrounds.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | using Gee; 18 | 19 | namespace BirdFont { 20 | 21 | public class ScaledBackgrounds : GLib.Object { 22 | ImageSurface original; 23 | ArrayList scaled; 24 | 25 | public ScaledBackgrounds (ImageSurface original) { 26 | this.original = original; 27 | scaled = new ArrayList (); 28 | 29 | ScaledBackground image = scale (0.01); 30 | scaled.add (image); 31 | 32 | for (double scale_factor = 0.1; scale_factor <= 1; scale_factor += 0.1) { 33 | image = scale (scale_factor); 34 | scaled.add (image); 35 | } 36 | } 37 | 38 | public ScaledBackground get_image (double scale) { 39 | foreach (ScaledBackground image in scaled) { 40 | if (image.get_scale () < scale) { 41 | continue; 42 | } 43 | 44 | return image; 45 | } 46 | 47 | return scaled.get (scaled.size - 1); 48 | } 49 | 50 | private ScaledBackground scale (double scale_factor) { 51 | ImageSurface scaled_image; 52 | 53 | if (scale_factor <= 0) { 54 | warning ("scale_factor <= 0"); 55 | scale_factor = 1; 56 | } 57 | 58 | int width = (int) (original.get_width () * scale_factor); 59 | int height = (int) (original.get_height () * scale_factor); 60 | 61 | scaled_image = new ImageSurface (Format.ARGB32, width, height); 62 | Context context = new Context (scaled_image); 63 | context.scale (scale_factor, scale_factor); 64 | context.set_source_surface (original, 0, 0); 65 | context.paint (); 66 | 67 | return new ScaledBackground (scaled_image, scale_factor); 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/OffsetTable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class OffsetTable : OtfTable { 18 | DirectoryTable directory_table; 19 | 20 | public uint16 num_tables = 0; 21 | uint16 search_range = 0; 22 | uint16 entry_selector = 0; 23 | uint16 range_shift = 0; 24 | 25 | public OffsetTable (DirectoryTable t) { 26 | id = "Offset table"; 27 | directory_table = t; 28 | } 29 | 30 | public override void parse (FontData dis) throws Error { 31 | Fixed version; 32 | 33 | dis.seek (offset); 34 | 35 | version = dis.read_fixed (); 36 | num_tables = dis.read_ushort (); 37 | search_range = dis.read_ushort (); 38 | entry_selector = dis.read_ushort (); 39 | range_shift = dis.read_ushort (); 40 | 41 | printd (@"Font file version $(version.get_string ())\n"); 42 | printd (@"Number of tables $num_tables\n"); 43 | } 44 | 45 | public void process () throws GLib.Error { 46 | FontData fd = new FontData (); 47 | Fixed version = 0x00010000; // sfnt version 1.0 for TTF CFF else use OTTO 48 | 49 | 50 | num_tables = (uint16) directory_table.get_tables ().size - 2; // number of tables, skip DirectoryTable and OffsetTable 51 | 52 | search_range = max_pow_2_less_than_i (num_tables) * 16; 53 | entry_selector = max_log_2_less_than_i (num_tables); 54 | range_shift = 16 * num_tables - search_range; 55 | 56 | fd.add_fixed (version); 57 | fd.add_u16 (num_tables); 58 | fd.add_u16 (search_range); 59 | fd.add_u16 (entry_selector); 60 | fd.add_u16 (range_shift); 61 | 62 | // skip padding for offset table 63 | 64 | this.font_data = fd; 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /libbirdfont/ColorTool.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class ColorTool : Tool { 20 | 21 | public double color_r = 0; 22 | public double color_g = 0; 23 | public double color_b = 0; 24 | public double color_a = 0; 25 | 26 | public signal void color_updated (); 27 | 28 | public ColorTool (string tooltip = "") { 29 | base (null, tooltip); 30 | 31 | color_updated.connect (() => { 32 | redraw (); 33 | GlyphCanvas.redraw (); 34 | }); 35 | } 36 | 37 | public Color get_color () { 38 | return new Color (color_r, color_g, color_b, color_a); 39 | } 40 | 41 | public void set_color (Color c) { 42 | color_r = c.r; 43 | color_g = c.g; 44 | color_b = c.b; 45 | color_a = c.a; 46 | color_updated (); 47 | } 48 | 49 | public void signal_color_updated () { 50 | color_updated (); 51 | } 52 | 53 | public override void draw_tool (Context cr, double px, double py) { 54 | double scale = Toolbox.get_scale (); 55 | double x = this.x - px; 56 | double y = this.y - py; 57 | double xt = x + w / 2 - 8 * scale; 58 | double yt = y + h / 2 - 8 * scale; 59 | 60 | base.draw_tool (cr, px, py); 61 | 62 | cr.save (); 63 | cr.set_source_rgba (color_r, color_g, color_b, 1); 64 | cr.rectangle (xt, yt, 16 * scale, 16 * scale); 65 | cr.fill (); 66 | cr.restore (); 67 | } 68 | 69 | public void set_r (double c) { 70 | color_r = c; 71 | } 72 | 73 | public void set_g (double c) { 74 | color_g = c; 75 | } 76 | 77 | public void set_b (double c) { 78 | color_b = c; 79 | } 80 | 81 | public void set_a (double c) { 82 | color_a = c; 83 | } 84 | 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /libbirdfont/LanguageSelectionTab.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Cairo; 15 | using Math; 16 | 17 | namespace BirdFont { 18 | 19 | public class LanguageSelectionTab : Table { 20 | 21 | public LanguageSelectionTab () { 22 | } 23 | 24 | public override Gee.ArrayList get_rows () { 25 | Gee.ArrayList rows = new Gee.ArrayList (); 26 | int i = 0; 27 | 28 | rows.add (new Row.headline (t_("Character Sets"))); 29 | 30 | foreach (string language in DefaultLanguages.names) { 31 | Row r = new Row.columns_1 (language, i, false); 32 | rows.add (r); 33 | i++; 34 | } 35 | 36 | return rows; 37 | } 38 | 39 | public override void update_rows () { 40 | redraw_area (0, 0, allocation.width, allocation.height); 41 | } 42 | 43 | public override void selected_row (Row row, int column, bool delete_button) { 44 | select_language (row.get_index ()); 45 | } 46 | 47 | void select_language (int row) { 48 | string iso_code; 49 | OverView overview; 50 | GlyphRange gr; 51 | TabBar tb = MainWindow.get_tab_bar (); 52 | 53 | return_if_fail (0 <= row < DefaultLanguages.codes.size); 54 | 55 | iso_code = DefaultLanguages.codes.get (row); 56 | Preferences.set ("language", iso_code); 57 | tb.close_display (this); 58 | 59 | overview = MainWindow.get_overview (); 60 | gr = new GlyphRange (); 61 | DefaultCharacterSet.use_default_range (gr); 62 | overview.set_current_glyph_range (gr); 63 | OverviewTools.update_overview_characterset (); 64 | FontDisplay.dirty_scrollbar = true; 65 | } 66 | 67 | public override string get_label () { 68 | return t_("Character Set"); 69 | } 70 | 71 | public override string get_name () { 72 | return "Character Set"; 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/CmapSubtableFormat12.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 2013 2014 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** Format 12 cmap subtable */ 18 | public class CmapSubtableFormat12 : CmapSubtable { 19 | 20 | FontData cmap_data; 21 | 22 | public CmapSubtableFormat12 () { 23 | } 24 | 25 | public override ushort get_platform () { 26 | return 3; 27 | } 28 | 29 | public override ushort get_encoding () { 30 | return 10; 31 | } 32 | 33 | public override FontData get_cmap_data () { 34 | return cmap_data; 35 | } 36 | 37 | public override void generate_cmap_data (GlyfTable glyf_table) throws GLib.Error { 38 | GlyphRange glyph_range = new GlyphRange (); 39 | Gee.ArrayList ranges; 40 | FontData fd = new FontData (); 41 | uint32 first_assigned; 42 | uint32 index; 43 | 44 | first_assigned = 1; 45 | 46 | foreach (GlyphCollection g in glyf_table.glyphs) { 47 | if (!g.is_unassigned () && g.get_unicode_character () < 0xFFFFFFFF) { 48 | glyph_range.add_single (g.get_unicode_character ()); 49 | } 50 | } 51 | 52 | ranges = glyph_range.get_ranges (); 53 | 54 | fd.add_u16 (12); // Format 55 | fd.add_u16 (0); // Reserved 56 | 57 | fd.add_u32 (16 + ranges.size * 12); // length 58 | 59 | fd.add_u32 (0); // Language 60 | fd.add_u32 ((uint32) ranges.size); // Number of groupings 61 | 62 | index = first_assigned; 63 | foreach (UniRange u in ranges) { 64 | 65 | if (u.start >= 0xFFFFFFFF || u.stop >= 0xFFFFFFFF) { 66 | warning ("Glyph range not supported by CmapSubtableFormat12."); 67 | } else { 68 | fd.add_u32 (u.start); 69 | fd.add_u32 (u.stop); 70 | fd.add_u32 (index); 71 | 72 | index += u.length (); 73 | } 74 | } 75 | 76 | cmap_data = fd; 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/MaxpTable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class MaxpTable : OtfTable { 18 | 19 | GlyfTable glyf_table; 20 | 21 | public uint16 num_glyphs = 0; 22 | 23 | public MaxpTable (GlyfTable g) { 24 | glyf_table = g; 25 | id = "maxp"; 26 | } 27 | 28 | public override void parse (FontData dis) 29 | requires (offset > 0 && length > 0) { 30 | Fixed format; 31 | 32 | dis.seek (offset); 33 | 34 | format = dis.read_fixed (); 35 | printd (@"Maxp version: $(format.get_string ())\n"); 36 | 37 | num_glyphs = dis.read_ushort (); 38 | 39 | if (format == 0x00005000) { 40 | return; 41 | } 42 | 43 | // Format 1.0 continues here 44 | } 45 | 46 | public void process () { 47 | FontData fd = new FontData(); 48 | 49 | // Version 0.5 for fonts with cff data and 1.0 for ttf 50 | fd.add_u32 (0x00010000); 51 | 52 | if (glyf_table.glyphs.size == 0) { 53 | warning ("Zero glyphs in maxp table."); 54 | } 55 | 56 | fd.add_u16 ((uint16) glyf_table.glyphs.size); // numGlyphs in the font 57 | 58 | fd.add_u16 (glyf_table.get_max_points ()); // max points 59 | fd.add_u16 (glyf_table.get_max_contours ()); // max contours 60 | fd.add_u16 (0); // max composite points 61 | fd.add_u16 (0); // max composite contours 62 | fd.add_u16 (1); // max zones 63 | fd.add_u16 (0); // twilight points 64 | fd.add_u16 (0); // max storage 65 | fd.add_u16 (0); // max function defs 66 | fd.add_u16 (0); // max instruction defs 67 | fd.add_u16 (0); // max stack elements 68 | fd.add_u16 (0); // max size of instructions 69 | fd.add_u16 (0); // max component elements 70 | fd.add_u16 (0); // component depth 71 | 72 | fd.pad (); 73 | 74 | this.font_data = fd; 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/KernSplitter.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class KernSplitter : GLib.Object { 18 | public Gee.ArrayList pairs; 19 | private KernList source_list; 20 | 21 | public KernSplitter (KernList kerning_list) { 22 | source_list = kerning_list; 23 | pairs = new Gee.ArrayList (); 24 | 25 | kerning_list.all_single_kern((pair) => { 26 | pairs.add (pair); 27 | }); 28 | } 29 | 30 | /** Prevent integer overflow in coverage table of the PairPos1 subtable. */ 31 | public bool is_full (KernList kerning_pairs) { 32 | uint length = 10; 33 | length += GposTable.pairs_offset_length (kerning_pairs); 34 | length += GposTable.pairs_set_length (kerning_pairs); 35 | 36 | return length > (uint16.MAX - 10); 37 | } 38 | 39 | public KernList get_subset (uint offset) { 40 | int count = 0; 41 | KernList result = new KernList (source_list.glyf_table); 42 | 43 | PairFormat1 current = new PairFormat1 (); 44 | current.left = 0xFFFF; 45 | 46 | for (uint i = offset; i < pairs.size; i++) { 47 | PairFormat1 next = pairs.get ((int) i); 48 | 49 | if (is_full (result)) { 50 | break; 51 | } 52 | 53 | if (next.left != current.left) { 54 | current = new PairFormat1 (); 55 | current.left = next.left; 56 | result.pairs.add (current); 57 | } 58 | 59 | if (unlikely (next.pairs.size != 1)) { 60 | warning ("Splitting kerning pairs failed. " 61 | + @"next.pairs.size: != $(next.pairs.size)"); 62 | } 63 | 64 | current.pairs.add (next.pairs.get (0)); 65 | count++; 66 | } 67 | 68 | foreach (PairFormat1 kerning in result.pairs) { 69 | result.num_pairs += kerning.pairs.size; 70 | } 71 | 72 | return result; 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /scripts/configfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Copyright (C) 2012, 2013 Eduardo Naufel Schettino and Johan Mattsson 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | """ 18 | 19 | from . import version 20 | 21 | VERSION = version.VERSION 22 | 23 | def write_config (prefix): 24 | print ("Writing Config.vala") 25 | 26 | vars = (('VERSION', VERSION), 27 | ('PREFIX', prefix), 28 | ) 29 | 30 | f = open('./libbirdfont/Config.vala', 'w+') 31 | f.write("// Don't edit this file -- it is generated by the build script\n") 32 | f.write("namespace BirdFont {\n") 33 | 34 | var_line = ' internal const string %s = "%s";\n' 35 | for name, value in vars: 36 | f.write(var_line % (name, value)) 37 | 38 | f.write("}") 39 | 40 | def write_compile_parameters(prefix, dest, cc, gee, valac, pkg_config, 41 | non_null, valacflags, cflags, ldflags): 42 | settings = { 43 | 'prefix': prefix, 44 | 'dest': dest, 45 | 'cc': cc, 46 | 'cflags': cflags, 47 | 'ldflags': ldflags, 48 | 'valac': valac, 49 | 'valacflags': valacflags, 50 | 'pkg-config': pkg_config, 51 | 'non_null': '--enable-experimental-non-null' if non_null else '', 52 | 'gee': gee, 53 | } 54 | def autoquote(v): 55 | if isinstance(v, str): 56 | return '"' + v + '"' 57 | else: 58 | return str(v) 59 | 60 | f = open('./scripts/config.py', 'w+') 61 | f.write("#!/usr/bin/python3\n") 62 | for k, v in settings.items(): 63 | f.write("%s = %s\n" % (k.upper().replace('-', '_'), autoquote(v))) 64 | 65 | f.write("SETTINGS = {\n") 66 | for k, v in settings.items(): 67 | f.write(' "%s": %s,\n' % (k, autoquote(v))) 68 | f.write("}\n") 69 | -------------------------------------------------------------------------------- /scripts/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2012, 2013, 2014 Johan Mattsson 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | rep="$(pwd)" 18 | repname="$(basename $(pwd))" 19 | 20 | mkdir -p build 21 | cd build 22 | rm -rf export 23 | mkdir -p export 24 | cd export 25 | 26 | version=$(cat ../../scripts/version.py | grep "VERSION = '" | grep -v "SO_VERSION" | sed -e "s:VERSION = '::" | sed "s:'.*::g") 27 | 28 | if ! git diff --exit-code > /dev/null; then 29 | echo "Uncommitted changes, commit before creating the release." 30 | exit 1 31 | fi 32 | 33 | git tag -s v$version -m "Version $version" 34 | 35 | if [ $? -ne 0 ] ; then 36 | echo "Can't create release tag" 37 | exit 1 38 | fi 39 | 40 | echo "Creating a release fo version $version" 41 | 42 | if [ $# -ne 0 -a $# -ne 2 ] ; then 43 | echo "Usage: $0 branch version" 44 | exit 1 45 | fi 46 | 47 | rm -rf birdfont-$version 48 | 49 | if [ "$1" = "" ] ; then 50 | echo "No branch specified, exporting master." 51 | git clone --depth 1 file://$rep 52 | else 53 | git clone --depth 1 -b $1 file://$rep 54 | fi 55 | 56 | mv $repname birdfont-$version 57 | 58 | rm -rf birdfont-$version/.git 59 | rm -rf birdfont-$version/.gitignore 60 | rm -rf birdfont-$version/.travis.yml 61 | 62 | cd birdfont-$version 63 | python3 ./scripts/complete_translations.py -t 93 -i 64 | rm -rf ./scripts/__pycache__ 65 | cd .. 66 | 67 | tar -cf birdfont-$version.tar birdfont-$version 68 | 69 | xz -z birdfont-$version.tar 70 | 71 | rm -rf ../birdfont-$version.tar.xz 72 | 73 | mv birdfont-$version.tar.xz ../ 74 | 75 | # build it to make sure that everything was checked in 76 | cd birdfont-$version && \ 77 | ./configure && \ 78 | ./scripts/linux_build.py && \ 79 | gpg --output ../../birdfont-$version.tar.xz.sig --detach-sig ../../birdfont-$version.tar.xz && \ 80 | cd .. && \ 81 | rm -rf ../export/birdfont-$version 82 | -------------------------------------------------------------------------------- /libbirdfont/BackgroundSelection.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class BackgroundSelection : GLib.Object { 18 | 19 | public string? assigned_glyph; 20 | public BackgroundImage? image; 21 | public BackgroundImage parent_image; 22 | 23 | public double x { 24 | get { 25 | return x_img * parent_image.img_scale_x + parent_image.img_middle_x; 26 | } 27 | 28 | set { 29 | x_img = (value - parent_image.img_middle_x) / parent_image.img_scale_x; 30 | } 31 | } 32 | 33 | public double y { 34 | get { 35 | return y_img * parent_image.img_scale_y + parent_image.img_middle_y; 36 | } 37 | 38 | set { 39 | y_img = (value - parent_image.img_middle_y) / parent_image.img_scale_y; 40 | } 41 | } 42 | 43 | public double w { 44 | get { 45 | return width * parent_image.img_scale_x; 46 | } 47 | 48 | set { 49 | width = value / parent_image.img_scale_x; 50 | } 51 | } 52 | 53 | public double h { 54 | get { 55 | return height * parent_image.img_scale_y; 56 | } 57 | 58 | set { 59 | height = value / parent_image.img_scale_y; 60 | } 61 | } 62 | 63 | public double height; 64 | public double width; 65 | public double x_img; 66 | public double y_img; 67 | 68 | public BackgroundSelection (BackgroundImage? img, BackgroundImage parent_img, 69 | double x, double y, double w, double h) { 70 | 71 | assigned_glyph = null; 72 | parent_image = parent_img; 73 | image = img; 74 | this.x = x; 75 | this.y = y; 76 | this.w = w; 77 | this.h = h; 78 | } 79 | 80 | public BackgroundSelection.absolute (BackgroundImage? img, BackgroundImage parent_img, 81 | double x_img, double y_img, double width, double height) { 82 | 83 | assigned_glyph = null; 84 | parent_image = parent_img; 85 | image = img; 86 | this.x_img = x_img; 87 | this.y_img = y_img; 88 | this.width = width; 89 | this.height = height; 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class OpenFontFormatWriter : Object { 18 | 19 | DataOutputStream os; 20 | DataOutputStream os_mac; 21 | DirectoryTable directory_table; 22 | 23 | public static Font font; 24 | 25 | public OpenFontFormatWriter (int units_per_em) { 26 | directory_table = new DirectoryTable (); 27 | HeadTable.init (units_per_em); 28 | } 29 | 30 | public static Font get_current_font () { 31 | return font; 32 | } 33 | 34 | public void open (File ttf, File ttf_mac) throws Error { 35 | if (ttf.query_exists () || ttf_mac.query_exists ()) { 36 | warning ("File exists in export."); 37 | throw new FileError.EXIST("OpenFontFormatWriter: file exists."); 38 | } 39 | 40 | os = new DataOutputStream(ttf.create (FileCreateFlags.REPLACE_DESTINATION)); 41 | os_mac = new DataOutputStream(ttf_mac.create (FileCreateFlags.REPLACE_DESTINATION)); 42 | } 43 | 44 | public void write_ttf_font (Font nfont) throws Error { 45 | long dl; 46 | uint8* data; 47 | Gee.ArrayList tables; 48 | FontData fd; 49 | uint l; 50 | 51 | font = nfont; 52 | 53 | directory_table.process (); 54 | tables = directory_table.get_tables (); 55 | 56 | dl = directory_table.get_font_file_size (); 57 | 58 | if (dl == 0) { 59 | warning ("font size is zero"); 60 | return; 61 | } 62 | 63 | foreach (OtfTable t in tables) { 64 | fd = t.get_font_data (); 65 | data = fd.table_data; 66 | l = fd.length_with_padding (); 67 | 68 | for (int j = 0; j < l; j++) { 69 | os.put_byte (data[j]); 70 | } 71 | } 72 | 73 | directory_table.process_mac (); 74 | 75 | foreach (OtfTable t in tables) { 76 | fd = t.get_font_data (); 77 | data = fd.table_data; 78 | l = fd.length_with_padding (); 79 | 80 | for (int j = 0; j < l; j++) { 81 | os_mac.put_byte (data[j]); 82 | } 83 | } 84 | } 85 | 86 | public void close () throws Error { 87 | os.close (); 88 | os_mac.close (); 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /libbirdfont/NativeWindow.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013, 2014, 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public interface NativeWindow : GLib.Object { 18 | 19 | public const int HIDDEN = 0; 20 | public const int VISIBLE = 1; 21 | 22 | public abstract void file_chooser (string title, FileChooser file_chooser_callback, uint flags); 23 | 24 | public abstract void update_window_size (); 25 | 26 | public abstract string get_clipboard_data (); 27 | public abstract void set_clipboard (string data); 28 | public abstract void set_inkscape_clipboard (string data); 29 | 30 | /** Notify the UI about the new font. */ 31 | public abstract void font_loaded (); 32 | 33 | /** Exit the application. */ 34 | public abstract void quit (); 35 | 36 | /** Convert an image to PNG format. */ 37 | public abstract bool convert_to_png (string from, string to); 38 | 39 | /** Export fonts in a background thread. */ 40 | public abstract void export_font (); 41 | 42 | /** Load font in a background thread. */ 43 | public abstract void load (); 44 | 45 | /** Save font in a background thread. */ 46 | public abstract void save (); 47 | 48 | /** Load images in a background thread. */ 49 | public abstract void load_background_image (); 50 | 51 | /** Run a background thread and block the gui. */ 52 | public abstract void run_background_thread (Task t); 53 | 54 | /** Run a background thread without blocking the gui. */ 55 | public abstract void run_non_blocking_background_thread (Task t); 56 | 57 | /** Copy text to clipboard. */ 58 | public abstract void set_clipboard_text (string text); 59 | 60 | /** Get text from clipboard. */ 61 | public abstract string get_clipboard_text (); 62 | 63 | /** @return true if the current font can be exported. */ 64 | public abstract bool can_export (); 65 | 66 | /** Set cursor visibility */ 67 | public abstract void set_cursor (int visible); 68 | 69 | /** Scale all offscreen buffers by this factor in order to 70 | * support high resolution screens. 71 | */ 72 | public abstract double get_screen_scale (); 73 | 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /libbirdfont/Widget.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public abstract class Widget : GLib.Object { 21 | 22 | public double margin_bottom = 0; 23 | public double widget_x = 0; 24 | public double widget_y = 0; 25 | 26 | public abstract double get_height (); 27 | public abstract double get_width (); 28 | public abstract void draw (Context cr); 29 | 30 | public WidgetAllocation allocation = new WidgetAllocation (); 31 | 32 | public static void draw_rounded_rectangle (Context cr, double x, double y, double w, double h, double radius) { 33 | // fixme radius is padding not margin 34 | cr.move_to (x, y + radius); 35 | cr.arc (x + radius, y + radius, radius, 2 * (PI / 2), 3 * (PI / 2)); 36 | cr.line_to (x + w - radius, y); 37 | cr.arc (x + w - radius, y + radius, radius, 3 * (PI / 2), 4 * (PI / 2)); 38 | cr.line_to (x + w, y + h); 39 | cr.arc (x + w - radius, y + h, radius, 4 * (PI / 2), 5 * (PI / 2)); 40 | cr.line_to (x + radius, y + h + radius); 41 | cr.arc (x + radius, y + h, radius, 5 * (PI / 2), 6 * (PI / 2)); 42 | cr.line_to (x, y + radius); 43 | cr.close_path (); 44 | } 45 | 46 | public virtual void layout () { 47 | } 48 | 49 | public bool is_over (double x, double y) { 50 | return widget_x <= x <= widget_x + get_width () 51 | && widget_y <= y <= widget_y + get_height (); 52 | } 53 | 54 | public bool is_on_screen () { 55 | return (widget_y <= 0 <= widget_y + get_height ()) 56 | || (widget_y <= allocation.height <= widget_y + get_height ()) 57 | || (0 <= widget_y <= allocation.height); 58 | } 59 | 60 | public virtual void key_press (uint keyval) { 61 | } 62 | 63 | public virtual void focus (bool enter) { 64 | } 65 | 66 | public virtual void button_press (uint button, double x, double y) { 67 | } 68 | 69 | public virtual void button_release (uint button, double x, double y) { 70 | } 71 | 72 | public virtual void double_click (uint button, double x, double y) { 73 | } 74 | 75 | public virtual bool motion (double x, double y) { 76 | return false; 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /libbirdfont/MenuItem.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class MenuItem : GLib.Object { 18 | 19 | public signal void action (); 20 | public Text label; 21 | public string identifier; 22 | 23 | public double y; 24 | 25 | // key bindings 26 | public uint modifiers = NONE; 27 | public unichar key = '\0'; 28 | 29 | public Gee.ArrayList displays = new Gee.ArrayList (); 30 | 31 | public MenuItem (string label, string identifier = "") { 32 | this.label = new Text (); 33 | this.label.set_text (label); 34 | this.identifier = identifier; 35 | y = 0; 36 | } 37 | 38 | public void add_display (string d) { 39 | displays.add (d); 40 | } 41 | 42 | /** @return true if a key binding can be used in @param display. */ 43 | public bool in_display (string display) { 44 | if (displays.size == 0) { 45 | return true; 46 | } 47 | 48 | foreach (string d in displays) { 49 | if (d == display) { 50 | return true; 51 | } 52 | } 53 | 54 | return false; 55 | } 56 | 57 | public string get_key_bindings () { 58 | string key_binding = ""; 59 | 60 | if (key != '\0') { 61 | key_binding += "("; 62 | 63 | if ((modifiers & CTRL) > 0) { 64 | key_binding += "Ctrl+"; 65 | } 66 | 67 | if ((modifiers & ALT) > 0) { 68 | key_binding += "Alt+"; 69 | } 70 | 71 | if ((modifiers & LOGO) > 0) { 72 | key_binding += "Command+"; 73 | 74 | } 75 | 76 | if ((modifiers & SHIFT) > 0) { 77 | key_binding += "Shift+"; 78 | } 79 | 80 | switch (key) { 81 | case Key.UP: 82 | key_binding += t_("UP"); 83 | break; 84 | case Key.DOWN: 85 | key_binding += t_("DOWN"); 86 | break; 87 | case Key.LEFT: 88 | key_binding += t_("LEFT"); 89 | break; 90 | case Key.RIGHT: 91 | key_binding += t_("RIGHT"); 92 | break; 93 | default: 94 | key_binding += (!) key.to_string (); 95 | break; 96 | } 97 | 98 | key_binding += ")"; 99 | } 100 | 101 | return key_binding; 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /libbirdfont/Renderer/CachedFont.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Gee; 16 | 17 | namespace BirdFont { 18 | 19 | public class CachedFont : GLib.Object { 20 | public Font? font; 21 | 22 | public double top_limit { 23 | get { return _top_limit; } 24 | set { _top_limit = value; } 25 | } 26 | 27 | public double bottom_limit { 28 | get { return _bottom_limit; } 29 | set { _bottom_limit = value; } 30 | } 31 | 32 | public double base_line = 0; 33 | double _top_limit = 92.77; // FIXME: load before first glyph 34 | double _bottom_limit = -24.4; 35 | 36 | static FallbackFont fallback_font { 37 | get { 38 | if (_fallback_font == null) { 39 | _fallback_font = new FallbackFont (); 40 | } 41 | 42 | return (!) _fallback_font; 43 | } 44 | } 45 | static FallbackFont? _fallback_font = null; 46 | 47 | public CachedFont (Font? font) { 48 | Glyph? g; 49 | Glyph glyph; 50 | 51 | this.font = font; 52 | 53 | g = get_glyph_by_name ("a"); 54 | if (g != null) { 55 | glyph = (!) g; 56 | base_line = glyph.baseline; 57 | top_limit = glyph.top_limit; 58 | bottom_limit = glyph.bottom_limit; 59 | } else { 60 | warning("No default chararacter found in font."); 61 | } 62 | } 63 | 64 | public Glyph? get_glyph_by_name (string name) { 65 | Glyph? g = null; 66 | Font f; 67 | Glyph glyph; 68 | 69 | if (font != null) { 70 | f = (!) font; 71 | g = f.get_glyph_by_name (name); 72 | 73 | if (g != null) { 74 | glyph = (!) g; 75 | glyph.top_limit = f.top_limit; 76 | glyph.baseline = f.base_line; 77 | glyph.bottom_limit = f.bottom_limit; 78 | } 79 | } 80 | 81 | if (g == null && name.char_count () == 1) { 82 | f = fallback_font.get_single_glyph_font (name.get_char (0)); 83 | g = f.get_glyph_by_name (name); 84 | 85 | if (g == null) { 86 | return null; 87 | } 88 | 89 | glyph = (!) g; 90 | glyph.top_limit = f.top_limit; 91 | glyph.baseline = f.base_line; 92 | glyph.bottom_limit = f.bottom_limit; 93 | } 94 | 95 | return g; 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/KernSubtable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class KernSubtable : GLib.Object { 18 | 19 | public delegate void KernIterator (Kern k); 20 | public delegate void PairFormat1Iterator (PairFormat1 k); 21 | 22 | public Gee.ArrayList pairs; 23 | public uint num_pairs; 24 | 25 | public KernSubtable () { 26 | pairs = new Gee.ArrayList (); 27 | num_pairs = 0; 28 | } 29 | 30 | public void add (PairFormat1 kerning_pair) { 31 | num_pairs += kerning_pair.pairs.size; 32 | pairs.add (kerning_pair); 33 | } 34 | 35 | /** @return the number of glyphs that is kerned on the left side in 36 | * pair pos format 1. 37 | */ 38 | public uint get_length_left () { 39 | return pairs.size; 40 | } 41 | 42 | /** @return the total number of pairs. */ 43 | public uint get_length () { 44 | return num_pairs; 45 | } 46 | 47 | public void all_kern (KernIterator iter, int limit) { 48 | int i = 0; 49 | foreach (PairFormat1 p in pairs) { 50 | foreach (Kern k in p.pairs) { 51 | if (unlikely (i >= limit)) { 52 | warning (@"Too many pairs. Limit: $limit"); 53 | return; 54 | } 55 | 56 | iter (k); 57 | i++; 58 | } 59 | } 60 | } 61 | 62 | public void all_pairs_format1 (PairFormat1Iterator iter, int limit = -1) { 63 | uint i = 0; 64 | 65 | foreach (PairFormat1 p in pairs) { 66 | if (unlikely (i >= limit && limit != -1)) { 67 | warning (@"Too many pairs. Limit: $limit"); 68 | return; 69 | } 70 | 71 | iter (p); 72 | 73 | i++; 74 | } 75 | } 76 | 77 | public uint get_pairs_set_length () { 78 | uint len = 0; 79 | 80 | all_pairs_format1 ((p) => { 81 | len += 2 + 4 * p.pairs.size; 82 | }); 83 | 84 | return len; 85 | } 86 | 87 | public uint get_pairs_offset_length () { 88 | return 2 * pairs.size; 89 | } 90 | 91 | public uint get_bytes_used () { 92 | return get_pairs_set_length () + get_pairs_offset_length (); 93 | } 94 | 95 | public void remove_last () { 96 | return_if_fail (pairs.size > 0); 97 | pairs.remove_at (pairs.size - 1); 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /libbirdfont/RectangleTool.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Math; 16 | using Cairo; 17 | 18 | namespace BirdFont { 19 | 20 | public class RectangleTool : Tool { 21 | 22 | Path rectangle = new Path (); 23 | 24 | double press_x = -1; 25 | double press_y = -1; 26 | 27 | bool resize = false; 28 | 29 | public RectangleTool (string n) { 30 | base (n, t_("Rectangle")); 31 | 32 | press_action.connect((self, b, x, y) => { 33 | press (b, x, y); 34 | }); 35 | 36 | release_action.connect((self, b, x, y) => { 37 | press_x = -1; 38 | press_y = -1; 39 | rectangle = new Path (); 40 | resize = false; 41 | }); 42 | 43 | move_action.connect ((self, x, y) => { 44 | move (x, y); 45 | }); 46 | } 47 | 48 | void move (double x, double y) { 49 | Glyph g; 50 | double x1, y1, x2, y2; 51 | 52 | if (resize) { 53 | g = MainWindow.get_current_glyph (); 54 | g.delete_path (rectangle); 55 | 56 | rectangle = new Path (); 57 | 58 | x1 = Glyph.path_coordinate_x (press_x); 59 | y1 = Glyph.path_coordinate_y (press_y); 60 | x2 = Glyph.path_coordinate_x (x); 61 | y2 = Glyph.path_coordinate_y (y); 62 | 63 | if (GridTool.is_visible ()) { 64 | GridTool.tie_coordinate (ref x1, ref y1); 65 | GridTool.tie_coordinate (ref x2, ref y2); 66 | } 67 | 68 | rectangle.add (x1, y1); 69 | rectangle.add (x2, y1); 70 | rectangle.add (x2, y2); 71 | rectangle.add (x1, y2); 72 | 73 | if (StrokeTool.add_stroke) { 74 | rectangle.stroke = StrokeTool.stroke_width; 75 | rectangle.line_cap = StrokeTool.line_cap; 76 | } 77 | 78 | rectangle.init_point_type (); 79 | rectangle.close (); 80 | 81 | g.add_path (rectangle); 82 | 83 | foreach (EditPoint e in rectangle.points) { 84 | rectangle.recalculate_linear_handles_for_point (e); 85 | } 86 | 87 | rectangle.reset_stroke (); 88 | rectangle.update_region_boundaries (); 89 | 90 | GlyphCanvas.redraw (); 91 | } 92 | } 93 | 94 | void press (int button, double x, double y) { 95 | press_x = x; 96 | press_y = y; 97 | resize = true; 98 | 99 | GlyphCanvas.redraw (); 100 | } 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/Lookup.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | /** Representation of one lookup in gsub and gpos tables. */ 18 | public class Lookup : GLib.Object { 19 | public uint16 type; 20 | public uint16 flags; 21 | public Gee.ArrayList subtables; 22 | public string token; 23 | 24 | public uint subtable_offset = 0; 25 | public uint entry_offset = 0; 26 | 27 | // the token is used for obtaining index in lookup list, an empty 28 | // string ensures that the subtable can't be directly used by 29 | // a table, chaining context use that feature. 30 | // 31 | // Lookups.find is used to obtain index in the lookup list for 32 | // a token. 33 | public Lookup (uint16 type, uint16 flags, string token = "") { 34 | this.type = type; 35 | this.flags = flags; 36 | subtables = new Gee.ArrayList (); 37 | this.token = token; 38 | subtable_offset = 0; 39 | } 40 | 41 | public void add_subtable (FontData subtable) { 42 | subtables.add (subtable); 43 | } 44 | 45 | public uint get_lookup_entry_size () throws GLib.Error { 46 | return get_lookup_entry (0).length_with_padding (); 47 | } 48 | 49 | public uint get_subtable_size () throws GLib.Error { 50 | uint size = 0; 51 | uint s; 52 | 53 | foreach (FontData subtable in subtables) { 54 | s = subtable.length_with_padding (); 55 | 56 | if (s == 0) { 57 | warning ("Zero size in subtable."); 58 | } 59 | 60 | size += s; 61 | } 62 | 63 | warn_if_fail (size != 0); 64 | 65 | return size; 66 | } 67 | 68 | public FontData get_lookup_entry (uint offset) 69 | throws GLib.Error { 70 | FontData fd = new FontData (); 71 | 72 | return_val_if_fail (subtables.size > 0, fd); 73 | 74 | fd.add_ushort (type); // lookup type 75 | fd.add_ushort (flags); // lookup flags 76 | fd.add_ushort ((uint16) subtables.size); // number of subtables 77 | 78 | // array of offsets to subtable 79 | uint s; 80 | 81 | foreach (FontData subtable in subtables) { 82 | fd.add_ushort ((uint16) offset); 83 | s = subtable.length_with_padding (); 84 | 85 | if (s == 0) { 86 | warning ("Zero size in subtable."); 87 | } 88 | 89 | offset += 2 + s; 90 | } 91 | 92 | return fd; 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /libbirdfont/SaveCallback.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class SaveCallback : GLib.Object { 18 | 19 | public signal void file_saved (); 20 | public bool is_done = false; 21 | 22 | public string font_file_path = ""; 23 | 24 | public SaveCallback () { 25 | file_saved.connect (() => { 26 | is_done = true; 27 | }); 28 | } 29 | 30 | public void save_as () { 31 | if (MenuTab.has_suppress_event ()) { 32 | warn_if_test ("Event suppressed"); 33 | return; 34 | } 35 | 36 | FileChooser fc = new FileChooser (); 37 | fc.file_selected.connect ((fn) => { 38 | string f; 39 | File file; 40 | OverwriteBfFile dialog; 41 | string file_name; 42 | 43 | is_done = true; 44 | 45 | if (fn != null) { 46 | f = (!) fn; 47 | 48 | #if MAC 49 | font_file_path = f; 50 | save (); 51 | #else 52 | if (!f.has_suffix (".bf") && !f.has_suffix (".birdfont")) { 53 | f = @"$f.birdfont"; 54 | } 55 | 56 | file_name = @"$(f)"; 57 | file = File.new_for_path (file_name); 58 | font_file_path = (!) file.get_path (); 59 | if (!file.query_exists ()) { 60 | save (); 61 | } else { 62 | dialog = new OverwriteBfFile (this); 63 | MainWindow.show_dialog (dialog); 64 | } 65 | #endif 66 | } 67 | }); 68 | 69 | fc.add_extension ("bf"); 70 | MainWindow.file_chooser (t_("Save"), fc, FileChooser.SAVE); 71 | } 72 | 73 | public void save () { 74 | Font f; 75 | string fn; 76 | 77 | if (MenuTab.has_suppress_event ()) { 78 | warn_if_test ("Event suppressed"); 79 | return; 80 | } 81 | 82 | f = BirdFont.get_current_font (); 83 | 84 | if (font_file_path != "") { 85 | f.font_file = font_file_path; 86 | } 87 | 88 | #if !MAC 89 | Preferences.add_recent_files (f.get_path ()); 90 | #endif 91 | 92 | if (f.is_bfp ()) { 93 | MainWindow.native_window.save (); 94 | } else { 95 | fn = f.get_path (); 96 | 97 | if (f.font_file != null 98 | && (fn.has_suffix (".bf") || fn.has_suffix (".birdfont"))) { 99 | 100 | f.set_font_file (fn); 101 | MainWindow.native_window.save (); 102 | } else { 103 | save_as (); 104 | } 105 | } 106 | } 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/CligFeature.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Math; 15 | 16 | namespace BirdFont { 17 | 18 | public class CligFeature : GLib.Object { 19 | public LigatureCollection clig; 20 | public ContextualLigatureCollection contextual; 21 | Lookups lookups; 22 | GlyfTable glyf_table; 23 | 24 | public CligFeature (GlyfTable glyf_table) throws GLib.Error { 25 | this.glyf_table = glyf_table; 26 | generate_feature (); 27 | } 28 | 29 | public bool has_regular_ligatures () { 30 | return clig.ligature_sets.size > 0; 31 | } 32 | 33 | public Lookups get_lookups () { 34 | return lookups; 35 | } 36 | 37 | private void generate_feature () throws GLib.Error { 38 | Gee.ArrayList chain_data; 39 | FontData clig_subtable; 40 | FontData fd; 41 | Lookup lookup; 42 | 43 | fd = new FontData (); 44 | clig = new LigatureCollection.clig (glyf_table); 45 | contextual = new ContextualLigatureCollection (glyf_table); 46 | 47 | clig_subtable = clig.get_font_data (glyf_table); 48 | clig_subtable.pad (); 49 | 50 | chain_data = get_chaining_contextual_substition_subtable (contextual); 51 | 52 | // lookup table 53 | lookups = new Lookups (); 54 | 55 | if (contextual.has_ligatures ()) { 56 | foreach (LigatureCollection s in contextual.ligatures) { 57 | lookup = new Lookup (4, 0, "chained data"); 58 | lookup.add_subtable (s.get_font_data (glyf_table)); 59 | lookups.add_lookup(lookup); 60 | } 61 | 62 | lookup = new Lookup (6, 0, "chain context"); 63 | foreach (FontData d in chain_data) { 64 | lookup.add_subtable (d); 65 | } 66 | lookups.add_lookup(lookup); 67 | } 68 | 69 | lookup = new Lookup (4, 0, "ligatures"); 70 | lookup.add_subtable (clig_subtable); 71 | lookups.add_lookup(lookup); 72 | } 73 | 74 | // chaining contextual substitution format3 75 | Gee.ArrayList get_chaining_contextual_substition_subtable (ContextualLigatureCollection contexts) throws GLib.Error { 76 | Gee.ArrayList fd = new Gee.ArrayList (); 77 | uint16 ligature_lookup_index = 0; 78 | 79 | foreach (ContextualLigature context in contexts.ligature_context) { 80 | fd.add (context.get_font_data (glyf_table, ligature_lookup_index)); 81 | ligature_lookup_index++; 82 | } 83 | 84 | return fd; 85 | } 86 | } 87 | 88 | } 89 | 90 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/Ligature.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class Ligature : GLib.Object { 18 | public string ligature = ""; 19 | public string substitution = ""; 20 | 21 | public Ligature (string ligature, string substitution = "") { 22 | this.ligature = ligature; 23 | this.substitution = substitution; 24 | } 25 | 26 | public unichar get_first_char () { 27 | unichar first; 28 | int index = 0; 29 | 30 | get_coverage (substitution).get_next_char (ref index, out first); 31 | 32 | return first; 33 | } 34 | 35 | public static string get_coverage (string ligatures) { 36 | string[] sp; 37 | unichar first; 38 | int index = 0; 39 | string characters = ligatures; 40 | 41 | if (characters.has_prefix ("U+") || characters.has_prefix ("u+")) { 42 | sp = characters.split (" "); 43 | return_val_if_fail (sp.length > 0, ""); 44 | characters = (!) Font.to_unichar (sp[0]).to_string (); 45 | } 46 | sp = characters.split (" "); 47 | 48 | if (sp.length == 0) { 49 | return ""; 50 | } 51 | 52 | if (sp[0] == "space") { 53 | sp[0] = " "; 54 | } 55 | 56 | sp[0].get_next_char (ref index, out first); 57 | 58 | return (!) first.to_string (); 59 | } 60 | 61 | public void set_ligature () { 62 | TextListener listener; 63 | 64 | listener = new TextListener (t_("Ligature"), ligature, t_("Set")); 65 | 66 | listener.signal_text_input.connect ((text) => { 67 | ligature = text; 68 | }); 69 | 70 | listener.signal_submit.connect (() => { 71 | TabContent.hide_text_input (); 72 | MainWindow.get_ligature_display ().update_rows (); 73 | }); 74 | 75 | TabContent.show_text_input (listener); 76 | } 77 | 78 | public void set_substitution () { 79 | TextListener listener; 80 | 81 | listener = new TextListener (t_("Text"), substitution, t_("Set")); 82 | 83 | listener.signal_text_input.connect ((text) => { 84 | Font f = BirdFont.get_current_font (); 85 | Ligatures l = f.get_ligatures (); 86 | substitution = text; 87 | l.sort_ligatures (); 88 | }); 89 | 90 | listener.signal_submit.connect (() => { 91 | TabContent.hide_text_input (); 92 | MainWindow.get_ligature_display ().update_rows (); 93 | }); 94 | 95 | TabContent.show_text_input (listener); 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /libbirdfont/OrientationTool.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Math; 16 | using Cairo; 17 | 18 | namespace BirdFont { 19 | 20 | public class OrientationTool : Tool { 21 | 22 | double time = 0; 23 | bool count_down = false; 24 | 25 | public OrientationTool (string name, string tip) { 26 | base (name, tip); 27 | 28 | set_icon ("orientation_both"); 29 | 30 | select_action.connect ((self) => { 31 | Glyph g = MainWindow.get_current_glyph (); 32 | 33 | foreach (Path p in g.active_paths) { 34 | p.reverse (); 35 | } 36 | 37 | count_down = true; 38 | Glyph.show_orientation_arrow = true; 39 | Glyph.orientation_arrow_opacity = 1; 40 | time = 10; 41 | fade_out (); 42 | 43 | update_icon (); 44 | GlyphCanvas.redraw (); 45 | }); 46 | 47 | DrawingTools.move_tool.selection_changed.connect (() => { 48 | update_icon (); 49 | }); 50 | } 51 | 52 | public void update_icon () { 53 | Glyph glyph = MainWindow.get_current_glyph (); 54 | bool has_clockwise_paths = false; 55 | bool has_counter_clockwise_paths = false; 56 | 57 | foreach (Path p in glyph.active_paths) { 58 | if (p.is_clockwise ()) { 59 | has_clockwise_paths = true; 60 | } 61 | 62 | if (!p.is_clockwise ()) { 63 | has_counter_clockwise_paths = true; 64 | } 65 | } 66 | 67 | if (has_clockwise_paths && has_counter_clockwise_paths) { 68 | set_icon ("orientation_both"); 69 | } else if (has_clockwise_paths) { 70 | set_icon ("orientation_clockwise"); 71 | } else if (has_counter_clockwise_paths) { 72 | set_icon ("orientation_counter_clockwise"); 73 | } else { 74 | set_icon ("orientation_both"); 75 | } 76 | 77 | Toolbox.redraw_tool_box (); 78 | } 79 | 80 | public void fade_out () { 81 | TimeoutSource timer = new TimeoutSource (100); 82 | timer.set_callback (() => { 83 | if (count_down) { 84 | if (time <= 0) { 85 | Glyph.show_orientation_arrow = false; 86 | count_down = false; 87 | } 88 | 89 | if (time < 1) { 90 | Glyph.orientation_arrow_opacity = time; 91 | GlyphCanvas.redraw (); 92 | } 93 | 94 | time -= 0.1; 95 | } else { 96 | Glyph.show_orientation_arrow = false; 97 | } 98 | 99 | return count_down; 100 | }); 101 | timer.attach (null); 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /libbirdfont/SpacingTools.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class SpacingTools : ToolCollection { 21 | public static Gee.ArrayList expanders; 22 | 23 | public static ZoomBar zoom_bar; 24 | 25 | public SpacingTools () { 26 | expanders = new Gee.ArrayList (); 27 | 28 | Expander font_name = new Expander (); 29 | font_name.add_tool (new FontName ()); 30 | 31 | Expander zoom_expander = new Expander (t_("Font Size")); 32 | 33 | zoom_bar = new ZoomBar (); 34 | zoom_bar.new_zoom.connect ((z) => { 35 | Font f; 36 | 37 | KerningTools.font_size = 3 * z; 38 | 39 | if (KerningTools.font_size < 0.1) { 40 | KerningTools.font_size = 0.1; 41 | } 42 | 43 | f = BirdFont.get_current_font (); 44 | f.settings.set_setting ("spacing_zoom", @"$z"); 45 | 46 | GlyphCanvas.redraw (); 47 | }); 48 | zoom_expander.add_tool (zoom_bar); 49 | 50 | Expander spacing_tools_expander = new Expander (); 51 | 52 | Tool insert_last = new Tool ("insert_glyph_from_overview", t_("Insert glyph from overview")); 53 | insert_last.select_action.connect ((self) => { 54 | SpacingTab d = MainWindow.get_spacing_tab (); 55 | GlyphSelection gs = new GlyphSelection (); 56 | 57 | gs.selected_glyph.connect ((gc) => { 58 | d.inser_glyph (gc.get_current ()); 59 | MainWindow.get_tab_bar ().select_tab_name ("Spacing"); 60 | }); 61 | 62 | GlyphCanvas.set_display (gs); 63 | self.set_selected (false); 64 | }); 65 | spacing_tools_expander.add_tool (insert_last); 66 | 67 | Tool insert_unicode = new Tool ("insert_unichar", t_("Insert character by unicode value")); 68 | insert_unicode.select_action.connect ((self) => { 69 | SpacingTab d = MainWindow.get_spacing_tab (); 70 | d.insert_unichar (); 71 | self.set_selected (false); 72 | }); 73 | spacing_tools_expander.add_tool (insert_unicode); 74 | 75 | spacing_tools_expander.add_tool (KerningTools.previous_kerning_string); 76 | spacing_tools_expander.add_tool (KerningTools.next_kerning_string); 77 | 78 | expanders.add (font_name); 79 | expanders.add (zoom_expander); 80 | expanders.add (spacing_tools_expander); 81 | } 82 | 83 | public override Gee.ArrayList get_displays () { 84 | Gee.ArrayList d = new Gee.ArrayList (); 85 | d.add ("Spacing"); 86 | return d; 87 | } 88 | 89 | public override Gee.ArrayList get_expanders () { 90 | return expanders; 91 | } 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /libbirdfont/GlyphMaster.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class GlyphMaster : GLib.Object { 21 | public Gee.ArrayList glyphs = new Gee.ArrayList (); 22 | public int selected = 0; 23 | 24 | public string id = "Master 1"; 25 | 26 | public GlyphMaster () { 27 | } 28 | 29 | public GlyphMaster.for_id (string id) { 30 | this.id = id; 31 | } 32 | 33 | public string get_id () { 34 | return id; 35 | } 36 | 37 | public void remove (int index) { 38 | return_if_fail (0 <= index < glyphs.size); 39 | 40 | if (selected >= index) { 41 | selected--; 42 | } 43 | 44 | glyphs.remove_at (index); 45 | } 46 | 47 | public void set_selected (Glyph g) { 48 | int i = 0; 49 | 50 | foreach (Glyph gl in glyphs) { 51 | if (gl == g) { 52 | selected = i; 53 | return; 54 | } 55 | i++; 56 | } 57 | 58 | selected = 0; 59 | warning ("Glyph is not a part of the collection."); 60 | } 61 | 62 | public void add_glyph (Glyph g) { 63 | glyphs.add (g); 64 | } 65 | 66 | public Glyph? get_current () { 67 | if (likely (0 <= selected < glyphs.size)) { 68 | return glyphs.get (selected); 69 | } 70 | 71 | warning (@"No glyph $selected glyphs.size: $(glyphs.size)"); 72 | 73 | return null; 74 | } 75 | 76 | public void insert_glyph (Glyph g, bool selected_glyph) { 77 | glyphs.add (g); 78 | 79 | if (selected_glyph) { 80 | selected = glyphs.size - 1; 81 | } 82 | } 83 | 84 | public void set_selected_version (int version_id) { 85 | int i = 0; 86 | foreach (Glyph g in glyphs) { 87 | if (g.version_id == version_id) { 88 | selected = i; 89 | break; 90 | } 91 | i++; 92 | } 93 | } 94 | 95 | public int get_last_id () { 96 | return_val_if_fail (glyphs.size > 0, 0); 97 | return glyphs.get (glyphs.size - 1).version_id; 98 | } 99 | 100 | public GlyphMaster copy_deep () { 101 | GlyphMaster n = new GlyphMaster (); 102 | 103 | foreach (Glyph g in glyphs) { 104 | n.glyphs.add (g.copy ()); 105 | } 106 | 107 | n.selected = selected; 108 | n.id = id; 109 | 110 | return n; 111 | } 112 | 113 | public GlyphMaster copy () { 114 | GlyphMaster n = new GlyphMaster (); 115 | 116 | foreach (Glyph g in glyphs) { 117 | n.glyphs.add (g); 118 | } 119 | 120 | n.selected = selected; 121 | n.id = id; 122 | 123 | return n; 124 | } 125 | } 126 | 127 | } 128 | 129 | -------------------------------------------------------------------------------- /libbirdfont/PreviewTools.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class PreviewTools : ToolCollection { 18 | public Gee.ArrayList expanders = new Gee.ArrayList (); 19 | public Expander classes; 20 | 21 | public PreviewTools () { 22 | Expander webview_tools = new Expander (); 23 | 24 | Expander font_name = new Expander (); 25 | font_name.add_tool (new FontName ()); 26 | 27 | Tool update_webview_button = new Tool ("update_webview", t_("Reload webview")); 28 | update_webview_button.select_action.connect ((self) => { 29 | update_preview (); 30 | }); 31 | webview_tools.add_tool (update_webview_button); 32 | 33 | Tool export_fonts_button = new Tool ("export_fonts", t_("Export fonts")); 34 | export_fonts_button.select_action.connect ((self) => { 35 | MenuTab.export_fonts_in_background (); 36 | }); 37 | webview_tools.add_tool (export_fonts_button); 38 | 39 | Tool generate_html_button = new Tool ("generate_html_document", t_("Generate html document")); 40 | generate_html_button.select_action.connect ((self) => { 41 | generate_html_document (); 42 | }); 43 | webview_tools.add_tool (generate_html_button); 44 | 45 | expanders.add (font_name); 46 | expanders.add (webview_tools); 47 | } 48 | 49 | /** Export fonts and update html canvas. */ 50 | public static void update_preview () { 51 | MenuTab.export_callback = new ExportCallback (); 52 | MenuTab.export_callback.preview = true; 53 | MenuTab.export_callback.file_exported.connect (signal_preview_updated); 54 | MenuTab.export_callback.export_fonts_in_background (); 55 | } 56 | 57 | private static void signal_preview_updated () { 58 | IdleSource idle = new IdleSource (); 59 | 60 | idle.set_callback (() => { 61 | if (!Preview.has_html_document ()) { 62 | Preview.generate_html_document (); 63 | } 64 | 65 | if (ExportTool.error_message == null) { 66 | MainWindow.tabs.select_tab_name ("Preview"); 67 | } 68 | 69 | return false; 70 | }); 71 | 72 | idle.attach (null); 73 | } 74 | 75 | /** Generate the preview document. */ 76 | public static void generate_html_document () { 77 | Preview.delete_html_document (); 78 | Preview.generate_html_document (); 79 | } 80 | 81 | public override Gee.ArrayList get_expanders () { 82 | return expanders; 83 | } 84 | 85 | public override Gee.ArrayList get_displays () { 86 | Gee.ArrayList d = new Gee.ArrayList (); 87 | d.add ("Preview"); 88 | return d; 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /libbirdfont/HiddenTools.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class HiddenTools : ToolCollection { 21 | 22 | public Gee.ArrayList expanders; 23 | public Expander hidden_expander; 24 | 25 | public static Tool bezier_line; 26 | public static Tool bezier_corner; 27 | public static Tool move_along_axis; 28 | 29 | public HiddenTools () { 30 | hidden_expander = new Expander (); 31 | expanders = new Gee.ArrayList (); 32 | 33 | Tool zoom_in = new Tool ("zoom_in", t_("Zoom in")); 34 | zoom_in.select_action.connect ((self) => { 35 | DrawingTools.zoom_tool.store_current_view (); 36 | GlyphCanvas.current_display.zoom_in (); 37 | }); 38 | hidden_expander.add_tool (zoom_in); 39 | 40 | Tool zoom_out = new Tool ("zoom_out", t_("Zoom out")); 41 | zoom_out.select_action.connect ((self) => { 42 | DrawingTools.zoom_tool.store_current_view (); 43 | GlyphCanvas.current_display.zoom_out (); 44 | }); 45 | hidden_expander.add_tool (zoom_out); 46 | 47 | bezier_line = new Tool ("bezier_line", t_("Convert the last segment to a straight line")); 48 | bezier_line.select_action.connect ((self) => { 49 | DrawingTools.bezier_tool.switch_to_line_mode (); 50 | }); 51 | bezier_line.is_tool_modifier = true; 52 | hidden_expander.add_tool (bezier_line); 53 | bezier_line.set_tool_visibility (false); 54 | 55 | bezier_corner = new Tool ("bezier_corner", t_("Convert the last control point to a corner node")); 56 | bezier_corner.select_action.connect ((self) => { 57 | DrawingTools.bezier_tool.create_corner (); 58 | }); 59 | bezier_corner.is_tool_modifier = true; 60 | hidden_expander.add_tool (bezier_corner); 61 | bezier_corner.set_tool_visibility (false); 62 | 63 | move_along_axis = new Tool ("bezier", t_("Move handle along axis")); 64 | move_along_axis.select_action.connect ((self) => { 65 | Tool t = MainWindow.get_toolbox ().get_current_tool (); 66 | if (t is BezierTool) { 67 | DrawingTools.bezier_tool.move_handle_on_axis (); 68 | } else if (t is PenTool || t is PointTool) { 69 | PenTool.move_handle_on_axis (); 70 | } else if (t is BackgroundTool) { 71 | BackgroundTool.move_handle_on_axis (); 72 | } 73 | }); 74 | move_along_axis.is_tool_modifier = true; 75 | hidden_expander.add_tool (move_along_axis); 76 | move_along_axis.set_tool_visibility (false); 77 | 78 | expanders.add (hidden_expander); 79 | } 80 | 81 | public override Gee.ArrayList get_expanders () { 82 | return expanders; 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /libbirdfont/KerningStrings.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class KerningStrings : GLib.Object { 18 | 19 | Gee.ArrayList kerning_strings = new Gee.ArrayList (); 20 | int current_position = 0; 21 | 22 | public KerningStrings () { 23 | } 24 | 25 | public bool is_empty () { 26 | return kerning_strings.size == 0; 27 | } 28 | 29 | public string next () { 30 | string w = ""; 31 | Font font = BirdFont.get_current_font (); 32 | 33 | if (0 <= current_position < kerning_strings.size) { 34 | w = kerning_strings.get (current_position); 35 | current_position++; 36 | font.settings.set_setting ("kerning_string_position", @"$current_position"); 37 | } 38 | 39 | return w; 40 | } 41 | 42 | public string previous () { 43 | string w = ""; 44 | Font font = BirdFont.get_current_font (); 45 | 46 | if (0 <= current_position - 1 < kerning_strings.size) { 47 | current_position--; 48 | w = kerning_strings.get (current_position); 49 | font.settings.set_setting ("kerning_string_position", @"$current_position"); 50 | } 51 | 52 | return w; 53 | 54 | } 55 | 56 | public void load_file () { 57 | FileChooser fc = new FileChooser (); 58 | fc.file_selected.connect ((f) => { 59 | Font font = BirdFont.get_current_font (); 60 | if (f != null) { 61 | load_new_string (font, (!) f); 62 | } 63 | }); 64 | 65 | MainWindow.file_chooser (t_("Load kerning strings"), fc, FileChooser.LOAD); 66 | } 67 | 68 | public void load (Font font) { 69 | string path; 70 | 71 | path = font.settings.get_setting ("kerning_string_file"); 72 | 73 | if (path != "") { 74 | load_new_string (font, path); 75 | current_position = int.parse (font.settings.get_setting ("kerning_string_position")); 76 | } 77 | } 78 | 79 | public void load_new_string (Font font, string kerning_strings_file) { 80 | string data; 81 | string[] strings; 82 | string w; 83 | 84 | try { 85 | kerning_strings.clear (); 86 | 87 | FileUtils.get_contents(kerning_strings_file, out data); 88 | strings = data.replace ("\n", " ").split (" "); 89 | 90 | foreach (string s in strings) { 91 | w = s.replace ("\r", ""); 92 | if (w != "") { 93 | kerning_strings.add (s); 94 | } 95 | } 96 | 97 | current_position = 0; 98 | 99 | font.settings.set_setting ("kerning_string_file", kerning_strings_file); 100 | } catch (GLib.Error e) { 101 | warning (e.message); 102 | } 103 | } 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /libbirdfont/SvgStyle.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using B; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class SvgStyle { 21 | 22 | Gee.HashMap style; 23 | 24 | public SvgStyle () { 25 | style = new Gee.HashMap (); 26 | } 27 | 28 | public LineCap get_line_cap () { 29 | string l; 30 | 31 | if (!style.has_key ("stroke-linecap")) { 32 | return LineCap.BUTT; 33 | } 34 | 35 | l = style.get ("stroke-linecap"); 36 | 37 | if (l == "round") { 38 | return LineCap.ROUND; 39 | } else if (l == "square") { 40 | return LineCap.SQUARE; 41 | } 42 | 43 | return LineCap.BUTT; 44 | } 45 | 46 | public bool has_stroke () { 47 | bool s = true; 48 | 49 | if (style.has_key ("stroke")) { 50 | s = style.get ("stroke") != "none"; 51 | } 52 | 53 | return get_stroke_width () > 0 && s; 54 | } 55 | 56 | public double get_stroke_width () { 57 | if (!style.has_key ("stroke-width")) { 58 | return 0; 59 | } 60 | 61 | return double.parse (style.get ("stroke-width")); 62 | } 63 | 64 | 65 | public static SvgStyle parse (Attributes attributes) { 66 | SvgStyle s = new SvgStyle (); 67 | 68 | foreach (Attribute a in attributes) { 69 | if (a.get_name () == "style") { 70 | s.parse_key_value_pairs (a.get_content ()); 71 | } 72 | 73 | if (a.get_name () == "stroke-width") { 74 | s.style.set ("stroke-width", a.get_content ()); 75 | } 76 | 77 | if (a.get_name () == "stroke") { 78 | s.style.set ("stroke", a.get_content ()); 79 | } 80 | 81 | if (a.get_name () == "fill") { 82 | s.style.set ("fill", a.get_content ()); 83 | } 84 | } 85 | 86 | return s; 87 | } 88 | 89 | void parse_key_value_pairs (string svg_style) { 90 | string[] p = svg_style.split (";"); 91 | string[] pair; 92 | string k, v; 93 | 94 | foreach (string kv in p) { 95 | pair = kv.split (":"); 96 | 97 | if (pair.length != 2) { 98 | warning ("pair.length != 2"); 99 | continue; 100 | } 101 | 102 | k = pair[0]; 103 | v = pair[1]; 104 | 105 | style.set (k, v); 106 | } 107 | } 108 | 109 | public void apply (PathList path_list) { 110 | foreach (Path p in path_list.paths) { 111 | if (has_stroke ()) { 112 | p.stroke = get_stroke_width (); 113 | } else { 114 | p.stroke = 0; 115 | } 116 | 117 | p.line_cap = get_line_cap (); 118 | p.reset_stroke (); 119 | p.update_region_boundaries (); 120 | } 121 | } 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /libbirdfont/GlyphCanvas.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Cairo; 15 | using Math; 16 | 17 | namespace BirdFont { 18 | 19 | public class GlyphCanvas : GLib.Object { 20 | 21 | /** Tab content. */ 22 | public static FontDisplay current_display; 23 | 24 | public signal void signal_redraw_area (int x, int y, int w, int h); 25 | public static WidgetAllocation allocation; 26 | 27 | public GlyphCanvas () { 28 | allocation = new WidgetAllocation (); 29 | } 30 | 31 | public static WidgetAllocation get_allocation () { 32 | return allocation; 33 | } 34 | 35 | public static void set_allocation (WidgetAllocation w) { 36 | allocation = w.copy (); 37 | } 38 | 39 | public void key_release (uint e) { 40 | current_display.key_release (e); 41 | } 42 | 43 | public void key_press (uint e) { 44 | current_display.key_press (e); 45 | } 46 | 47 | public static void set_display (FontDisplay fd) { 48 | current_display = fd; 49 | } 50 | 51 | public void set_current_glyph_collection (GlyphCollection gc, bool signal_selected = true) { 52 | Glyph g = gc.get_current (); 53 | 54 | BirdFont.current_glyph_collection = gc; 55 | g.resized (allocation); 56 | 57 | if (!is_null (current_display)) { 58 | if (signal_selected) { 59 | current_display.selected_canvas (); 60 | FontDisplay.dirty_scrollbar = true; 61 | } 62 | 63 | current_display.redraw_area.connect ((x, y, w, h) => { 64 | signal_redraw_area ((int)x, (int)y, (int)w, (int)h); 65 | }); 66 | 67 | redraw (); 68 | } 69 | 70 | if (!is_null (MainWindow.native_window)) { 71 | MainWindow.native_window.update_window_size (); 72 | } 73 | } 74 | 75 | public static Glyph get_current_glyph () { 76 | return MainWindow.get_current_glyph (); 77 | } 78 | 79 | public FontDisplay get_current_display () { 80 | return current_display; 81 | } 82 | 83 | public void redraw_area (int x, int y, int w, int h) { 84 | if (MenuTab.has_suppress_event ()) { 85 | warning ("Do not call redraw from background thread."); 86 | } else { 87 | signal_redraw_area (x, y, w + (int) MainWindow.scrollbar.width, h); 88 | } 89 | } 90 | 91 | public static void redraw () { 92 | GlyphCanvas c = MainWindow.get_glyph_canvas (); 93 | if (!is_null (c) && !is_null (MainWindow.scrollbar)) { 94 | int w = (int) (allocation.width + MainWindow.scrollbar.width); 95 | c.redraw_area (0, 0, w, allocation.height); 96 | } 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/OtfTable.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012, 2013 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class OtfTable : Object { 18 | 19 | public string id = "NO_ID"; 20 | 21 | public uint32 checksum = 0; 22 | public uint32 offset = 0; 23 | public uint32 length = 0; 24 | 25 | protected FontData? font_data = null; 26 | 27 | public virtual string get_id () { 28 | return id; 29 | } 30 | 31 | public FontData get_font_data () { 32 | if (font_data == null) { 33 | warning (@"No font data for $(id)."); 34 | font_data = new FontData (); 35 | } 36 | 37 | return (!) font_data; 38 | } 39 | 40 | public bool has_data () { 41 | return length > 0; 42 | } 43 | 44 | public virtual void parse (FontData dis) throws GLib.Error { 45 | warning (@"Parse is not implemented for $(id)."); 46 | } 47 | 48 | /** Validate table checksum. */ 49 | public bool validate (FontData dis) { 50 | bool valid; 51 | 52 | if (length == 0) { 53 | stderr.printf (@"OtfTable $id is of zero length.\n"); 54 | valid = false; 55 | } else { 56 | valid = OtfTable.validate_table (dis, checksum, offset, length, id); 57 | } 58 | 59 | if (!valid) { 60 | stderr.printf (@"OtfTable $id is invalid.\n"); 61 | } 62 | 63 | return valid; 64 | } 65 | 66 | public static bool validate_table (FontData dis, uint32 checksum, uint32 offset, uint32 length, string name) { 67 | uint32 ch = calculate_checksum (dis, offset, length, name); 68 | bool c; 69 | 70 | c = (ch == checksum); 71 | 72 | if (!c) { 73 | stderr.printf(@"Checksum does not match data for $(name).\n"); 74 | stderr.printf(@"name: $name, checksum: $checksum, offset: $offset, length: $length\n"); 75 | stderr.printf(@"calculated checksum $(ch)\n"); 76 | } 77 | 78 | return c; 79 | } 80 | 81 | public static uint32 calculate_checksum (FontData dis, uint32 offset, uint32 length, string name) { 82 | uint32 checksum = 0; 83 | uint32 l; 84 | 85 | dis.seek (offset); 86 | 87 | l = (length % 4 > 0) ? length / 4 + 1 : length / 4; 88 | 89 | for (uint32 i = 0; i < l; i++) { 90 | checksum += dis.read_ulong (); 91 | } 92 | 93 | return checksum; 94 | } 95 | 96 | public static uint16 max_pow_2_less_than_i (uint16 ind) { 97 | uint16 last = 0; 98 | uint16 i = 1; 99 | 100 | while ((i <<= 1) < ind) { 101 | last = i; 102 | } 103 | 104 | return last; 105 | } 106 | 107 | public static uint16 max_log_2_less_than_i (uint16 ind) { 108 | return (uint16) (Math.log (ind) / Math.log (2)); 109 | } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /libbirdfont/OpenFontFormat/Lookups.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | using Math; 15 | 16 | namespace BirdFont { 17 | 18 | // Contextual substitutions uses this table for chained substitutions, 19 | // the order is not arbitrary. 20 | 21 | public class Lookups : GLib.Object { 22 | public Gee.ArrayList tables = new Gee.ArrayList (); 23 | 24 | public Lookups () { 25 | } 26 | 27 | /** Subtables added in the proirity order for the substitution or 28 | * spacing transformation. The first table will have highest 29 | * priority. 30 | */ 31 | public void add_lookup (Lookup lookup) { 32 | tables.add (lookup); 33 | } 34 | 35 | /** Find the lookup index for a particular lookup. */ 36 | public uint16 find (string token) { 37 | uint16 index = 0; 38 | foreach (Lookup lookup in tables) { 39 | if (lookup.token == token) { 40 | return index; 41 | } 42 | 43 | index++; 44 | } 45 | 46 | warning (@"No lookup has been created with token $(token)"); 47 | return 0; 48 | } 49 | 50 | public void append (Lookups lookups) { 51 | foreach (Lookup lookup in lookups.tables) { 52 | tables.add (lookup); 53 | } 54 | } 55 | 56 | public FontData generate_lookup_list () throws GLib.Error { 57 | FontData fd = new FontData (); 58 | FontData entry; 59 | uint lookup_offset; 60 | 61 | fd.add_ushort ((uint16) tables.size); // number of lookups 62 | lookup_offset = 2 + 2 * tables.size; 63 | 64 | foreach (Lookup lookup in tables) { 65 | fd.add_ushort ((uint16) lookup_offset); 66 | lookup_offset += lookup.get_lookup_entry_size (); 67 | } 68 | 69 | // add empty lookups and step back when tables are written 70 | foreach (Lookup lookup in tables) { 71 | entry = lookup.get_lookup_entry (0); 72 | lookup.entry_offset = fd.length_with_padding (); 73 | fd.append (entry); 74 | } 75 | 76 | if (lookup_offset != fd.length_with_padding ()) { 77 | warning ("Wrong lookup offset."); 78 | warning (@"$lookup_offset != $(fd.length_with_padding ())"); 79 | } 80 | 81 | foreach (Lookup lookup in tables) { 82 | uint offset_pos = lookup.entry_offset + 6; 83 | fd.seek (offset_pos); 84 | 85 | uint offset = (fd.length_with_padding () - (lookup.entry_offset)); 86 | foreach (FontData f in lookup.subtables) { 87 | fd.add_ushort ((uint16) offset); 88 | offset += f.length_with_padding (); 89 | } 90 | fd.seek_end (); 91 | 92 | foreach (FontData subtable in lookup.subtables) { 93 | fd.append (subtable); 94 | } 95 | } 96 | 97 | return fd; 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /libbirdfont/Intersection.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class Intersection : GLib.Object { 21 | public bool done = false; 22 | public EditPoint point; 23 | public EditPoint other_point; 24 | public Path path; 25 | public Path other_path; 26 | public bool self_intersection = false; 27 | 28 | public Intersection (EditPoint point, Path path, 29 | EditPoint other_point, Path other_path) { 30 | 31 | this.point = point; 32 | this.path = path; 33 | this.other_point = other_point; 34 | this.other_path = other_path; 35 | } 36 | 37 | public Intersection.empty () { 38 | this.point = new EditPoint (); 39 | this.path = new Path (); 40 | this.other_point = new EditPoint (); 41 | this.other_path = new Path (); 42 | } 43 | 44 | public Path get_other_path (Path p) { 45 | if (p == path) { 46 | return other_path; 47 | } 48 | 49 | if (p == other_path) { 50 | return path; 51 | } 52 | 53 | warning (@"Wrong intersection."); 54 | return new Path (); 55 | } 56 | 57 | public EditPoint get_point (Path p) { 58 | if (p == path) { 59 | return point; 60 | } 61 | 62 | if (p == other_path) { 63 | return other_point; 64 | } 65 | 66 | warning ("Wrong intersection."); 67 | return new EditPoint (); 68 | } 69 | 70 | public EditPoint get_other_point (Path p) { 71 | if (p == path) { 72 | return other_point; 73 | } 74 | 75 | if (p == other_path) { 76 | return point; 77 | } 78 | 79 | warning ("Wrong intersection."); 80 | return new EditPoint (); 81 | } 82 | 83 | public string to_string () { 84 | return @"$(point.x), $(point.y) & $(other_point.x), $(other_point.y)"; 85 | } 86 | } 87 | 88 | public class IntersectionList : GLib.Object { 89 | public Gee.ArrayList points = new Gee.ArrayList (); 90 | 91 | public IntersectionList () { 92 | } 93 | 94 | public Intersection get_point (EditPoint ep, out bool other) { 95 | other = false; 96 | foreach (Intersection i in points) { 97 | if (likely (i.other_point == ep || i.point == ep)) { 98 | other = (i.other_point == ep); 99 | return i; 100 | } 101 | } 102 | 103 | warning (@"No intersection found for point ($(ep.x), $(ep.y)).\n"); 104 | 105 | return new Intersection.empty (); 106 | } 107 | 108 | public bool has_point (EditPoint ep) { 109 | foreach (Intersection i in points) { 110 | if (i.other_point == ep || i.point == ep) { 111 | return true; 112 | } 113 | } 114 | 115 | return false; 116 | } 117 | 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /libbirdfont/CheckBox.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class CheckBox : Widget { 21 | 22 | public bool checked = false; 23 | public signal void updated (bool checked); 24 | public double padding = 3.333 * MainWindow.units; 25 | 26 | public double w = 12 * MainWindow.units; 27 | public double h = 12 * MainWindow.units; 28 | 29 | bool has_focus = false; 30 | 31 | public Text label; 32 | 33 | public CheckBox (string text = "", double font_size = -1) { 34 | if (font_size < 0) { 35 | font_size = h; 36 | } 37 | 38 | label = new Text (text, font_size); 39 | Theme.text_color (label, "Text Foreground"); 40 | } 41 | 42 | public void set_checked (bool c) { 43 | checked = c; 44 | updated (c); 45 | } 46 | 47 | public override double get_height () { 48 | return label.font_size; 49 | } 50 | 51 | public override double get_width () { 52 | return w + 2 * padding + label.get_sidebearing_extent (); 53 | } 54 | 55 | public override void draw (Context cr) { 56 | double d = w * 0.25; 57 | double center_y = (get_height () - (h + 2 * padding)) / 2.0 + padding; 58 | 59 | cr.save (); 60 | Theme.color (cr, "Checkbox Background"); 61 | draw_rounded_rectangle (cr, widget_x, widget_y + center_y, w, h - padding, padding); 62 | cr.fill (); 63 | cr.restore (); 64 | 65 | cr.save (); 66 | cr.set_line_width (1); 67 | 68 | if (has_focus) { 69 | Theme.color (cr, "Highlighted 1"); 70 | } else { 71 | Theme.color (cr, "Text Foreground"); 72 | } 73 | 74 | draw_rounded_rectangle (cr, widget_x, widget_y + center_y, w, h - padding, padding); 75 | cr.stroke (); 76 | cr.restore (); 77 | 78 | if (checked) { 79 | cr.save (); 80 | 81 | Theme.color (cr, "Text Foreground"); 82 | cr.set_line_width (1); 83 | 84 | cr.move_to (widget_x + d, widget_y + d + center_y); 85 | cr.line_to (widget_x + w - d, widget_y + h - d + center_y); 86 | cr.stroke (); 87 | 88 | cr.move_to (widget_x + w - d, widget_y + d + center_y); 89 | cr.line_to (widget_x + d, widget_y + h - d + center_y); 90 | cr.stroke (); 91 | 92 | cr.restore (); 93 | } 94 | 95 | label.widget_x = widget_x + 1.5 * w; 96 | label.widget_y = widget_y; 97 | label.draw (cr); 98 | } 99 | 100 | public override void key_press (uint keyval) { 101 | unichar c = (unichar) keyval; 102 | 103 | if (c == ' ') { 104 | checked = !checked; 105 | } 106 | } 107 | 108 | public override void focus (bool focus) { 109 | has_focus = focus; 110 | } 111 | 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /libbirdfont/MessageDialog.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | 17 | namespace BirdFont { 18 | 19 | public class MessageDialog : Dialog { 20 | 21 | public Button ok_button; 22 | TextArea message; 23 | public signal void close (); 24 | 25 | public MessageDialog (string message) { 26 | Color c = Theme.get_color ("Text Tool Box"); 27 | this.message = new TextArea (20 * MainWindow.units, c); 28 | this.message.set_text (message); 29 | this.message.draw_border = false; 30 | this.message.editable = false; 31 | this.message.carret_is_visible = false; 32 | this.message.min_width = 300 * MainWindow.units; 33 | this.message.width = this.message.min_width; 34 | this.message.min_height = 20 * MainWindow.units; 35 | this.message.height = this.message.min_height; 36 | 37 | ok_button = new Button (t_("Close")); 38 | ok_button.action.connect (close_action); 39 | } 40 | 41 | public void close_action () { 42 | close (); 43 | MainWindow.hide_dialog (); 44 | } 45 | 46 | public override void draw (Context cr) { 47 | double cx, cy; 48 | double width, height; 49 | 50 | message.layout (); 51 | 52 | width = message.get_width (); 53 | width += 10 * MainWindow.units; 54 | 55 | height = message.get_height (); 56 | height += ok_button.get_height (); 57 | height += 5 * MainWindow.units; 58 | 59 | cx = (allocation.width - width) / 2.0; 60 | cy = (allocation.height - height) / 2.0; 61 | 62 | cr.save (); 63 | Theme.color_opacity (cr, "Foreground 1", 0.3); 64 | cr.rectangle (0, 0, allocation.width, allocation.height); 65 | cr.fill (); 66 | cr.restore (); 67 | 68 | cr.save (); 69 | Theme.color (cr, "Dialog Background"); 70 | draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 71 | cr.fill (); 72 | cr.restore (); 73 | 74 | cr.save (); 75 | Theme.color (cr, "Foreground 1"); 76 | cr.set_line_width (1); 77 | draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units); 78 | cr.stroke (); 79 | cr.restore (); 80 | 81 | cy += 5 * MainWindow.units; 82 | message.widget_x = cx + 10 * MainWindow.units; 83 | message.widget_y = cy; 84 | message.allocation = allocation; 85 | message.layout (); 86 | message.draw (cr); 87 | 88 | ok_button.widget_x = cx + 10 * MainWindow.units; 89 | ok_button.widget_y = cy + message.get_height (); 90 | ok_button.draw (cr); 91 | } 92 | 93 | public override void button_press (uint button, double x, double y) { 94 | ok_button.button_press (button, x, y); 95 | } 96 | 97 | public override void button_release (uint button, double x, double y) { 98 | ok_button.button_release (button, x, y); 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /libbirdfont/AlternateSets.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | namespace BirdFont { 16 | 17 | public class AlternateSets : GLib.Object { 18 | 19 | public Gee.ArrayList alternates; 20 | 21 | public AlternateSets () { 22 | alternates = new Gee.ArrayList (); 23 | } 24 | 25 | public Gee.ArrayList get_all_tags () { 26 | Gee.ArrayList tags; 27 | tags = new Gee.ArrayList (); 28 | 29 | foreach (Alternate a in alternates) { 30 | if (tags.index_of (a.tag) == -1) { 31 | tags.add (a.tag); 32 | } 33 | } 34 | 35 | tags.sort ((a, b) => { 36 | return strcmp ((string) a, (string) b); 37 | }); 38 | 39 | return tags; 40 | } 41 | 42 | public Gee.ArrayList get_alt (string tag) { 43 | Gee.ArrayList alt; 44 | alt = new Gee.ArrayList (); 45 | 46 | foreach (Alternate a in alternates) { 47 | if (a.tag == tag && a.alternates.size > 0) { 48 | alt.add (a); 49 | } 50 | } 51 | 52 | return alt; 53 | } 54 | 55 | public Gee.ArrayList get_alt_with_glyph (string tag, Font font) { 56 | Gee.ArrayList alt; 57 | alt = new Gee.ArrayList (); 58 | 59 | foreach (Alternate a in alternates) { 60 | Alternate available = new Alternate (a.glyph_name, a.tag); 61 | 62 | foreach (string substitution in a.alternates) { 63 | if (font.has_glyph (substitution)) { 64 | available.alternates.add (substitution); 65 | } 66 | } 67 | 68 | if (available.tag == tag && available.alternates.size > 0) { 69 | if (font.has_glyph (available.glyph_name)) { 70 | alt.add (available); 71 | } 72 | } 73 | } 74 | 75 | return alt; 76 | } 77 | 78 | public void remove_empty_sets () { 79 | int i = 0; 80 | foreach (Alternate a in alternates) { 81 | if (a.is_empty ()) { 82 | alternates.remove_at (i); 83 | remove_empty_sets (); 84 | return; 85 | } 86 | i++; 87 | } 88 | } 89 | 90 | public void add (Alternate alternate) { 91 | alternates.add (alternate); 92 | } 93 | 94 | public AlternateSets copy () { 95 | AlternateSets n = new AlternateSets (); 96 | foreach (Alternate a in alternates) { 97 | n.alternates.add (a.copy ()); 98 | } 99 | return n; 100 | } 101 | } 102 | 103 | public class AlternateItem : GLib.Object { 104 | public Alternate alternate_list; 105 | public string alternate; 106 | 107 | public AlternateItem (Alternate alternate_list, string alternate) { 108 | this.alternate_list = alternate_list; 109 | this.alternate = alternate; 110 | } 111 | 112 | public void delete_item_from_list () { 113 | alternate_list.remove_alternate (alternate); 114 | } 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /libbirdfont/BackgroundSelectionTool.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using Cairo; 16 | using Math; 17 | 18 | namespace BirdFont { 19 | 20 | public class BackgroundSelectionTool : CutBackgroundTool { 21 | 22 | public BackgroundSelectionTool () { 23 | base ("select_background", t_("Select background")); 24 | editor_events = true; 25 | persistent = true; 26 | self_destination = false; 27 | 28 | new_image.connect (add_new_image); 29 | 30 | select_action.connect ((t) => { 31 | DrawingTools.move_canvas.set_selected (false); 32 | GlyphCanvas.redraw (); 33 | }); 34 | 35 | draw_action.connect ((self, cr, glyph) => { 36 | double x, y, w, h; 37 | BackgroundImage bg; 38 | Text label = new Text (); 39 | double tx, ty, font_height; 40 | 41 | if (glyph.get_background_image () == null) { 42 | // No image to draw. 43 | return; 44 | } 45 | 46 | // draw a border around each selection 47 | bg = (!) glyph.get_background_image (); 48 | foreach (BackgroundSelection bs in bg.selections) { 49 | x = Glyph.reverse_path_coordinate_x (bs.x); 50 | y = Glyph.reverse_path_coordinate_y (bs.y); 51 | w = Glyph.reverse_path_coordinate_x (bs.x + bs.w) - x; 52 | h = Glyph.reverse_path_coordinate_y (bs.y + bs.h) - y; 53 | 54 | cr.save (); 55 | cr.set_line_width (2.0); 56 | 57 | if (bs.assigned_glyph != null) { 58 | cr.set_source_rgba (237 / 255.0, 67 / 255.0, 0, 1); 59 | } else { 60 | cr.set_source_rgba (132 / 255.0, 132 / 255.0, 132 / 255.0, 1); 61 | } 62 | 63 | cr.rectangle (x, y, w, h); 64 | cr.stroke (); 65 | 66 | cr.arc (x + w, y + h, 9.0, 0, 2 * PI); 67 | cr.fill (); 68 | 69 | if (bs.assigned_glyph != null) { 70 | font_height = 18; 71 | label.set_text ((!) bs.assigned_glyph); 72 | label.set_font_size (font_height); 73 | tx = x + w - label.get_width () / 2.0; 74 | ty = y + h + label.get_acender () / 2.0 - label.get_decender (); 75 | label.set_font_size (font_height); 76 | label.draw_at_baseline (cr, tx, ty); 77 | } 78 | 79 | cr.restore (); 80 | } 81 | }); 82 | } 83 | 84 | public void add_new_image (BackgroundImage image, 85 | double x, double y, double w, double h) { 86 | 87 | BackgroundImage bg; 88 | BackgroundSelection selection; 89 | 90 | if (MainWindow.get_current_glyph ().get_background_image () == null) { 91 | warning ("No image"); 92 | return; 93 | } 94 | 95 | bg = (!) MainWindow.get_current_glyph ().get_background_image (); 96 | selection = new BackgroundSelection (image, bg, x, y, w, h); 97 | 98 | bg.add_selection (selection); 99 | Toolbox.background_tools.add_part (selection); 100 | } 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /libbirdfont/SvgTransform.vala: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 2019 Johan Mattsson 3 | 4 | This library is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation; either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | */ 14 | 15 | using B; 16 | using Cairo; 17 | 18 | namespace BirdFont { 19 | 20 | public enum TransformType { 21 | NONE, 22 | TRANSLATE, 23 | MATRIX, 24 | SCALE, 25 | ROTATE 26 | } 27 | 28 | public class SvgTransform : GLib.Object { 29 | public TransformType type = TransformType.NONE; 30 | public Doubles arguments = new Doubles.for_capacity (10); 31 | 32 | public SvgTransform () { 33 | } 34 | 35 | public SvgTransform.for_matrix (Matrix matrix) { 36 | type = TransformType.MATRIX; 37 | 38 | arguments.add (matrix.xx); 39 | arguments.add (matrix.yx); 40 | arguments.add (matrix.xy); 41 | arguments.add (matrix.yy); 42 | arguments.add (matrix.x0); 43 | arguments.add (matrix.y0); 44 | } 45 | 46 | public SvgTransform copy () { 47 | SvgTransform transform = new SvgTransform (); 48 | transform.type = type; 49 | transform.arguments = arguments.copy (); 50 | return transform; 51 | } 52 | 53 | public string to_string () { 54 | StringBuilder sb = new StringBuilder (); 55 | 56 | sb.append (@"$type"); 57 | sb.append (" "); 58 | 59 | for (int i = 0; i < arguments.size; i++) { 60 | sb.append (@"$(arguments.get_double (i)) "); 61 | } 62 | 63 | return sb.str; 64 | } 65 | 66 | public Matrix get_matrix () { 67 | Matrix matrix; 68 | 69 | matrix = Matrix.identity (); 70 | 71 | if (type == TransformType.ROTATE) { 72 | if (arguments.size == 1) { 73 | double r = arguments.get_double (0); 74 | r *= Math.PI / 180; 75 | matrix.rotate (r); 76 | } 77 | } else if (type == TransformType.SCALE) { 78 | if (arguments.size == 1) { 79 | double s = arguments.get_double (0); 80 | matrix.scale (s, s); 81 | } else if (arguments.size == 2) { 82 | double s0 = arguments.get_double (0); 83 | double s1 = arguments.get_double (1); 84 | matrix.scale (s0, s1); 85 | } 86 | } else if (type == TransformType.TRANSLATE) { 87 | if (arguments.size == 1) { 88 | double s = arguments.get_double (0); 89 | matrix.translate (s, 0); 90 | } else if (arguments.size == 2) { 91 | double s0 = arguments.get_double (0); 92 | double s1 = arguments.get_double (1); 93 | matrix.translate (s0, s1); 94 | } 95 | } else if (type == TransformType.MATRIX) { 96 | if (arguments.size == 6) { 97 | double s0 = arguments.get_double (0); 98 | double s1 = arguments.get_double (1); 99 | double s2 = arguments.get_double (2); 100 | double s3 = arguments.get_double (3); 101 | double s4 = arguments.get_double (4); 102 | double s5 = arguments.get_double (5); 103 | 104 | matrix = Matrix (s0, s1, s2, s3, s4, s5); 105 | } 106 | } 107 | 108 | return matrix; 109 | } 110 | } 111 | 112 | } 113 | --------------------------------------------------------------------------------
10 | BirdFont is a font editor which can generate fonts in TTF, 11 | EOT and SVG format. 12 |