Full Code of ayoy/fontedit for AI

develop 9fdf7bfce507 cached
82 files
335.1 KB
93.0k tokens
170 symbols
1 requests
Download .txt
Showing preview only (357K chars total). Download the full file or copy to clipboard to get everything.
Repository: ayoy/fontedit
Branch: develop
Commit: 9fdf7bfce507
Files: 82
Total size: 335.1 KB

Directory structure:
gitextract_t8uykv9z/

├── .gitignore
├── .gitmodules
├── CHANGELOG.md
├── CMakeLists.txt
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── app/
│   ├── CMakeLists.txt
│   ├── addglyphdialog.cpp
│   ├── addglyphdialog.h
│   ├── addglyphdialog.ui
│   ├── assets.qrc
│   ├── cmake_uninstall.cmake.in
│   ├── command.h
│   ├── common/
│   │   ├── CMakeLists.txt
│   │   ├── common.h
│   │   ├── f2b_qt_compat.cpp
│   │   └── f2b_qt_compat.h
│   ├── fontfaceviewmodel.cpp
│   ├── fontfaceviewmodel.h
│   ├── global.h
│   ├── l10n/
│   │   ├── fontedit_en.qm
│   │   └── fontedit_en.ts
│   ├── macos/
│   │   ├── Info.plist
│   │   └── fontedit.icns
│   ├── main.cpp
│   ├── mainwindow.cpp
│   ├── mainwindow.h
│   ├── mainwindow.ui
│   ├── mainwindowmodel.cpp
│   ├── mainwindowmodel.h
│   ├── qfontfacereader.cpp
│   ├── qfontfacereader.h
│   ├── semver.hpp
│   ├── sourcecoderunnable.cpp
│   ├── sourcecoderunnable.h
│   ├── ui/
│   │   ├── CMakeLists.txt
│   │   ├── aboutdialog.cpp
│   │   ├── aboutdialog.h
│   │   ├── aboutdialog.ui
│   │   ├── batchpixelchange.h
│   │   ├── facewidget.cpp
│   │   ├── facewidget.h
│   │   ├── focuswidget.cpp
│   │   ├── focuswidget.h
│   │   ├── glyphgraphicsview.cpp
│   │   ├── glyphgraphicsview.h
│   │   ├── glyphinfowidget.cpp
│   │   ├── glyphinfowidget.h
│   │   ├── glyphwidget.cpp
│   │   └── glyphwidget.h
│   ├── updatehelper.cpp
│   ├── updatehelper.h
│   ├── utf8/
│   │   ├── CMakeLists.txt
│   │   ├── utf8/
│   │   │   ├── checked.h
│   │   │   ├── core.h
│   │   │   └── unchecked.h
│   │   └── utf8.h
│   ├── win/
│   │   └── fontedit.rc
│   └── x11/
│       └── fontedit.desktop
├── fontedit.iss
├── lib/
│   ├── CMakeLists.txt
│   ├── src/
│   │   ├── CMakeLists.txt
│   │   ├── f2b.h
│   │   ├── fontdata.cpp
│   │   ├── fontdata.h
│   │   ├── fontsourcecodegenerator.cpp
│   │   ├── fontsourcecodegenerator.h
│   │   ├── format.h
│   │   ├── include/
│   │   │   └── f2b.h
│   │   └── sourcecode.h
│   └── test/
│       ├── CMakeLists.txt
│       ├── fontface_test.cpp
│       ├── glyph_test.cpp
│       └── sourcecode_test.cpp
└── test/
    ├── CMakeLists.txt
    ├── assets/
    │   ├── jetbrains260.fontedit
    │   ├── monaco8-subset.c-test
    │   ├── monaco8.c-test
    │   └── monaco8.fontedit
    ├── f2b_qt_compat_test.cpp
    └── sourcecodegeneration_test.cpp

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.dll
*.dylib

# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*

# Qt unit tests
target_wrapper.*

# QtCreator
*.autosave

# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*

# QtCreator CMake
CMakeLists.txt.user*
.DS_Store
.idea
*~
.*~
*.cbp
build


================================================
FILE: .gitmodules
================================================
[submodule "gsl"]
	path = gsl
	url = https://github.com/microsoft/GSL.git
[submodule "gtest"]
	path = gtest
	url = https://github.com/google/googletest.git


================================================
FILE: CHANGELOG.md
================================================
# Changelog

## 1.1.0 - 2020-05-31
* Export subset of font characters (only the characters that you really
  need in the font) - helps to reduce font size when you only use a bunch
  of characters and not the whole ASCII table
* Exported source code is wrapped at around 80 columns
* Added pseudocode in the generated source code, explaining how to retrieve
  individual font glyphs
* More user-friendly Undo/Redo functionality
* Added checking for updates on-demand from the menu and automatically
  at start-up (the latter can be disabled)


## 1.0.0 - 2020-03-20
* First public release
* Importing system fonts
* Editing font glyphs
* Adding new glyphs
* Exporting source code
* Saving current state of the font document


================================================
FILE: CMakeLists.txt
================================================
cmake_minimum_required(VERSION 3.9)
project(FontEdit)

set(CMAKE_PROJECT_VERSION_MAJOR 1)
set(CMAKE_PROJECT_VERSION_MINOR 1)
set(CMAKE_PROJECT_VERSION_PATCH 0)

set(APP_VERSION 1.1.0)
set(APP_BUILD 4)
set(APP_YEAR 2020)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(BUILD_TESTS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

find_package(Qt5 COMPONENTS Widgets REQUIRED)

enable_testing()
add_subdirectory(gtest EXCLUDE_FROM_ALL)
add_subdirectory(gsl EXCLUDE_FROM_ALL)
add_subdirectory(lib)
add_subdirectory(app)
if(${BUILD_TESTS})
    add_subdirectory(test)
endif()

if (APPLE)
    add_custom_command(OUTPUT "${APP_TARGET_NAME}.dmg"
        COMMAND macdeployqt
        ARGS "${APP_TARGET_NAME}.app" "-libpath=/lib" "-dmg"
        MAIN_DEPENDENCY ${APP_TARGET_NAME}.app
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

    add_custom_target(dmg
        DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${APP_TARGET_NAME}.dmg"
        )
elseif (WIN32)
    message(STATUS "ADDING WINDOWS INSTALLER TARGET")
    add_custom_command(OUTPUT "win"
        COMMAND windeployqt.exe
        ARGS "${APP_TARGET_NAME}.exe" "--dir" "win"
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

    add_custom_target(installer
        DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/win"
        )
endif ()


set(CPACK_PACKAGE_VERSION "1.1.0")
set(CPACK_PACKAGE_CONTACT "dominik@kapusta.cc")
set(CPACK_PROJECT_HOMEPAGE_URL "https://kapusta.cc")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_NAME "fontedit")
set(CPACK_DEBIAN_PACKAGE_RELEASE 3)
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION
    "Edit and convert fonts to byte arrays suitable for use in embedded systems' displays")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
include(CPack)


================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
 advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
 address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
 professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at dominik@kapusta.cc. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq


================================================
FILE: LICENSE
================================================
                    GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The GNU General Public License is a free, copyleft license for
software and other kinds of works.

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

  To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights.  Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received.  You must make sure that they, too, receive
or can get the source code.  And you must show them these terms so they
know their rights.

  Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.

  For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software.  For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.

  Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so.  This is fundamentally incompatible with the aim of
protecting users' freedom to change the software.  The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable.  Therefore, we
have designed this version of the GPL to prohibit the practice for those
products.  If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.

  Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary.  To prevent this, the GPL assures that
patents cannot be used to render the program non-free.

  The precise terms and conditions for copying, distribution and
modification follow.

                       TERMS AND CONDITIONS

  0. Definitions.

  "This License" refers to version 3 of the GNU General Public License.

  "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.

  "The Program" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as "you".  "Licensees" and
"recipients" may be individuals or organizations.

  To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.

  A "covered work" means either the unmodified Program or a work based
on the Program.

  To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.

  To "convey" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.

  An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.

  1. Source Code.

  The "source code" for a work means the preferred form of the work
for making modifications to it.  "Object code" means any non-source
form of a work.

  A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.

  The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.

  The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.

  The Corresponding Source for a work in source code form is that
same work.

  2. Basic Permissions.

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.

  5. Conveying Modified Source Versions.

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    "keep intact all notices".

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.

  6. Conveying Non-Source Forms.

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.

  A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.

  "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.

  7. Additional Terms.

  "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.

  All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.

  8. Termination.

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.

  9. Acceptance Not Required for Having Copies.

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.

  An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.

  11. Patents.

  A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's "contributor version".

  A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.

  In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.

  A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.

  12. No Surrender of Others' Freedom.

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.

  13. Use with the GNU Affero General Public License.

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.

  14. Revised Versions of this License.

  The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.

  If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.

  15. Disclaimer of Warranty.

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. Limitation of Liability.

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.

  17. Interpretation of Sections 15 and 16.

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

  If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

    <program>  Copyright (C) <year>  <name of author>
    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

  You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.

  The GNU General Public License does not permit incorporating your program
into proprietary programs.  If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.  But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

================================================
FILE: README.md
================================================
# FontEdit

FontEdit is a desktop application that allows you to convert general-purpose 
fixed-width desktop fonts to byte array representation that's suitable for
use in embedded systems displays.

It's written in C++ with Qt UI and was tested on Windows, Linux and MacOS.

Read more about it in [the blog post](https://kapusta.cc/2019/03/20/fontedit/).

![FontEdit](https://kapusta.cc/assets/fontedit/imported_font.png)

## Features

With FontEdit you can:

* import fonts from the operating system - to load a custom font, you should
  first register it in your OS,
* edit individual font glyphs after importing - automatic import is a best-effort
  operation and although the font should be usable right after importing, you
  might want to tweak it so that it looks better,
* add new glyphs to a font document - either by copying an existing glyph, starting 
  from scratch or adding a glyph from a character you input (useful for adding
  non-ASCII characters to your font),
* export the font as source code (in a form of byte array) suitable for Arduino,
  C/C++ or Python,
* save your progress to a file - the font document file is cross-platform so you can
  e.g. import and edit it on MacOS and then move to RPi and export the code from there,
* as of 1.1.0 you can do partial exports, i.e. export only a bunch of font characters
  that you really need for your application (read more in 
  [this blog post](https://kapusta.cc/2020/05/31/fontedit-1-1-0)).

### Font Editor

You can edit font glyphs with a minimal editor that's controlled with a mouse
and keyboard. Click and drag the mouse to set pixels (making them black), hold
Alt or Ctrl (⌘) to erase. Use touchpad scroll (mouse wheel) with Ctrl (⌘) to zoom
the editor canvas.

You can also reset the current glyph or the whole font to their initial state
(from latest save). The editor supports Undo/Redo for most operations.

### Source Code Export

The font data can be exported to:

* a C file (also suitable for use with C++),
* an Arduino-specific C file (using PROGMEM),
* a Python list or bytes object (both compatible with Python 2.x/3.x and MicroPython).

You can switch between MSB and LSB mode, invert all the bits, and conditionally include
line spacings in font definition (not recommended unless you have a very good reason
for it). The tab size can be configured.

## Getting FontEdit

### Packages

The [Releases GitHub page](https://github.com/ayoy/fontedit/releases) contains
packages for:
* Ubuntu/Debian (amd64),
* Raspbian Buster (armhf),
* MacOS,
* Windows.

### Building from source

Prerequisites:

* Qt (tested with >= 5.9)
* cmake (3.9 or newer)
* C++ compiler that supports C++17

Follow these steps to build the app from the source code:

1. Clone the Git repository:

    ```
    $ git clone https://github.com/ayoy/fontedit
    $ cd fontedit
    ```

2. Check out Git submodules:

    ```
    $ git submodule update --init
    ```

3. Build with CMake:

    ```
    $ mkdir build
    $ cd build
    $ cmake -DCMAKE_BUILD_TYPE=Release ..
    $ make
    ```

4. (Optionally) Install on Linux with: `make install` or create a dmg
  image on MacOS with `make dmg`.

## Bugs, ideas, improvements

Please report bugs and feature requests via [GitHub Issues](https://github.com/ayoy/fontedit/issues) or as a [pull request](https://github.com/ayoy/fontedit/pulls).

## License

© 2020 Dominik Kapusta

This app is distributed in accordance with GPL v3. See [LICENSE](https://github.com/ayoy/fontedit/blob/master/LICENSE) for details.
The app uses icons from [www.flaticon.com](https://www.flaticon.com) made by
[Smashicons](https://www.flaticon.com/authors/smashicons),
[Freepik](https://www.flaticon.com/authors/freepik) and
[Pixel perfect](https://www.flaticon.com/authors/pixel-perfect).


================================================
FILE: app/CMakeLists.txt
================================================
cmake_minimum_required(VERSION 3.9)

if (UNIX AND NOT APPLE)
    project(fontedit LANGUAGES CXX)
else()
    project(FontEdit LANGUAGES CXX)
endif()

set(APP_TARGET_NAME ${PROJECT_NAME} PARENT_SCOPE)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED)
find_package(Qt5LinguistTools)

add_subdirectory(utf8)
add_subdirectory(common)
add_subdirectory(ui)

set(SRC_FILES
    addglyphdialog.cpp
    addglyphdialog.h
    addglyphdialog.ui
    command.h
    fontfaceviewmodel.cpp
    fontfaceviewmodel.h
    global.h
    mainwindow.cpp
    mainwindow.h
    mainwindow.ui
    mainwindowmodel.cpp
    mainwindowmodel.h
    qfontfacereader.cpp
    qfontfacereader.h
    semver.hpp
    sourcecoderunnable.cpp
    sourcecoderunnable.h
    updatehelper.cpp
    updatehelper.h
    )

add_library(appbundle ${SRC_FILES})
target_include_directories(appbundle PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} utf8 common ui)
target_link_libraries(appbundle PUBLIC Qt5::Widgets Qt5::Core Qt5::Network common ui font2bytes GSL)

if (APPLE)
    message(STATUS "Building MacOS X Bundle")
    add_executable(${PROJECT_NAME} MACOSX_BUNDLE
        main.cpp
        assets.qrc
        )

    set(CMAKE_OSX_DEPLOYMENT_TARGET 10.14)
    set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/macos/Info.plist)
    set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE fontedit.icns)

    set(RESOURCES_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources)
    file(MAKE_DIRECTORY ${RESOURCES_DIR})
    file(COPY ${PROJECT_SOURCE_DIR}/macos/fontedit.icns DESTINATION ${RESOURCES_DIR})
elseif(WIN32)
    set(OPENSSL_ROOT_DIR "${Qt5_DIR}/../../../../Tools/OpenSSL/Win_x64" CACHE STRING "OpenSSL dir")
    include(FindOpenSSL)
    add_executable(${PROJECT_NAME} WIN32
        main.cpp
        assets.qrc
        win/fontedit.rc
        )
    target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
else()
    add_executable(${PROJECT_NAME}
        main.cpp
        assets.qrc
        )
    if (UNIX)
        install(TARGETS ${PROJECT_NAME}
            RUNTIME DESTINATION bin
            LIBRARY DESTINATION lib)
        install(FILES x11/fontedit.desktop DESTINATION share/applications)
        install(DIRECTORY x11/icons DESTINATION share)

        # uninstall target
        if(NOT TARGET uninstall)
            configure_file(
                "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
                "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
                IMMEDIATE @ONLY)

            add_custom_target(uninstall
            COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
        endif()

    endif()
endif()

target_include_directories(${PROJECT_NAME} PRIVATE appbundle)
target_link_libraries(${PROJECT_NAME} PRIVATE appbundle)

target_compile_definitions(${PROJECT_NAME} PRIVATE VERSION="${APP_VERSION}" BUILD="${APP_BUILD}" YEAR="${APP_YEAR}")
target_compile_definitions(appbundle PRIVATE VERSION="${APP_VERSION}" BUILD="${APP_BUILD}" YEAR="${APP_YEAR}")
target_compile_definitions(ui PRIVATE VERSION="${APP_VERSION}" BUILD="${APP_BUILD}" YEAR="${APP_YEAR}")


================================================
FILE: app/addglyphdialog.cpp
================================================
#include "addglyphdialog.h"
#include "./ui_addglyphdialog.h"
#include "facewidget.h"
#include "qfontfacereader.h"

AddGlyphDialog::AddGlyphDialog(const FontFaceViewModel& faceViewModel, QWidget *parent) :
    QDialog(parent),
    ui_ { new Ui::AddGlyphDialog }
{
    ui_->setupUi(this);

    faceScene_->setBackgroundBrush(QBrush(Qt::lightGray));
    faceWidget_ = new FaceWidget(7);

    ui_->titleLabel->setText(tr("Add a new Glyph to %1").arg(faceViewModel.faceInfo().fontName));

    ui_->faceGraphicsView->setScene(faceScene_.get());
    ui_->faceGraphicsView->scene()->addItem(faceWidget_);

    faceWidget_->load(faceViewModel.face(), f2b::font::margins {});
    connect(faceWidget_, &FaceWidget::currentGlyphIndexChanged, ui_->copyRadio, &QRadioButton::click);
    connect(faceWidget_, &FaceWidget::currentGlyphIndexChanged, [&, faceViewModel](std::optional<std::size_t> index) {
        if (index.has_value())
            newGlyph_ = faceViewModel.face().glyph_at(index.value());
    });
    connect(ui_->buttonBox, &QDialogButtonBox::accepted, [&, faceViewModel] {
        if (ui_->emptyRadio->isChecked()) {
            newGlyph_ = f2b::font::glyph { faceViewModel.face().glyphs_size() };
        } else if (ui_->characterRadio->isChecked()) {
            QFontFaceReader adapter {
                faceViewModel.font().value(),
                ui_->characterLineEdit->text().toStdString(),
                faceViewModel.face().glyphs_size()
            };
            newGlyph_ = f2b::font::face(adapter).glyph_at(0);
        }
        emit glyphSelected(newGlyph_);
    });

    if (faceViewModel.font().has_value()) {
        ui_->characterRadio->setEnabled(true);
        ui_->characterErrorLabel->setVisible(false);
        ui_->characterLineEdit->setVisible(true);
    } else {
        ui_->characterRadio->setEnabled(false);
        ui_->characterErrorLabel->setVisible(true);
        ui_->characterLineEdit->setVisible(false);
    }
}

AddGlyphDialog::~AddGlyphDialog()
{
    delete ui_;
}


================================================
FILE: app/addglyphdialog.h
================================================
#ifndef ADDGLYPHDIALOG_H
#define ADDGLYPHDIALOG_H

#include <QDialog>
#include <QGraphicsScene>
#include <memory>
#include <optional>
#include "fontfaceviewmodel.h"
#include "f2b.h"

namespace Ui {
class AddGlyphDialog;
}

class FaceWidget;

class AddGlyphDialog : public QDialog
{
    Q_OBJECT

public:
    explicit AddGlyphDialog(const FontFaceViewModel& faceViewModel, QWidget *parent = nullptr);
    ~AddGlyphDialog();

signals:
    void glyphSelected(const std::optional<f2b::font::glyph>& glyph);

private:
    Ui::AddGlyphDialog *ui_;
    FaceWidget *faceWidget_ { nullptr };
    std::unique_ptr<QGraphicsScene> faceScene_ { std::make_unique<QGraphicsScene>() };

    std::optional<f2b::font::glyph> newGlyph_ {};
};

#endif // ADDGLYPHDIALOG_H


================================================
FILE: app/addglyphdialog.ui
================================================
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>AddGlyphDialog</class>
 <widget class="QDialog" name="AddGlyphDialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>624</width>
    <height>539</height>
   </rect>
  </property>
  <property name="maximumSize">
   <size>
    <width>624</width>
    <height>16777215</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>Add New Glyph</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout">
   <property name="spacing">
    <number>8</number>
   </property>
   <item>
    <widget class="QLabel" name="titleLabel">
     <property name="text">
      <string>Adding Glyph for </string>
     </property>
    </widget>
   </item>
   <item>
    <layout class="QHBoxLayout" name="horizontalLayout_2">
     <item>
      <widget class="QRadioButton" name="emptyRadio">
       <property name="text">
        <string>Add empty Glyph</string>
       </property>
       <property name="checked">
        <bool>true</bool>
       </property>
      </widget>
     </item>
    </layout>
   </item>
   <item>
    <layout class="QHBoxLayout" name="horizontalLayout">
     <item>
      <widget class="QRadioButton" name="characterRadio">
       <property name="enabled">
        <bool>true</bool>
       </property>
       <property name="text">
        <string>Initialize with font character:</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QLabel" name="characterErrorLabel">
       <property name="enabled">
        <bool>false</bool>
       </property>
       <property name="text">
        <string>Current document font not found in system</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QLineEdit" name="characterLineEdit">
       <property name="enabled">
        <bool>true</bool>
       </property>
       <property name="maxLength">
        <number>1</number>
       </property>
       <property name="placeholderText">
        <string>Type character here</string>
       </property>
      </widget>
     </item>
     <item>
      <spacer name="horizontalSpacer">
       <property name="orientation">
        <enum>Qt::Horizontal</enum>
       </property>
       <property name="sizeHint" stdset="0">
        <size>
         <width>40</width>
         <height>20</height>
        </size>
       </property>
      </spacer>
     </item>
    </layout>
   </item>
   <item>
    <layout class="QHBoxLayout" name="horizontalLayout_3">
     <item>
      <widget class="QRadioButton" name="copyRadio">
       <property name="text">
        <string>Copy existing Glyph:</string>
       </property>
      </widget>
     </item>
    </layout>
   </item>
   <item>
    <widget class="QGraphicsView" name="faceGraphicsView">
     <property name="enabled">
      <bool>true</bool>
     </property>
    </widget>
   </item>
   <item>
    <widget class="QDialogButtonBox" name="buttonBox">
     <property name="orientation">
      <enum>Qt::Horizontal</enum>
     </property>
     <property name="standardButtons">
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <tabstops>
  <tabstop>emptyRadio</tabstop>
  <tabstop>characterRadio</tabstop>
  <tabstop>characterLineEdit</tabstop>
  <tabstop>copyRadio</tabstop>
  <tabstop>faceGraphicsView</tabstop>
 </tabstops>
 <resources/>
 <connections>
  <connection>
   <sender>buttonBox</sender>
   <signal>rejected()</signal>
   <receiver>AddGlyphDialog</receiver>
   <slot>reject()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>328</x>
     <y>534</y>
    </hint>
    <hint type="destinationlabel">
     <x>286</x>
     <y>274</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>characterLineEdit</sender>
   <signal>textChanged(QString)</signal>
   <receiver>characterRadio</receiver>
   <slot>click()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>583</x>
     <y>86</y>
    </hint>
    <hint type="destinationlabel">
     <x>179</x>
     <y>78</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>buttonBox</sender>
   <signal>accepted()</signal>
   <receiver>AddGlyphDialog</receiver>
   <slot>accept()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>378</x>
     <y>522</y>
    </hint>
    <hint type="destinationlabel">
     <x>8</x>
     <y>344</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>


================================================
FILE: app/assets.qrc
================================================
<RCC>
    <qresource prefix="/toolbar">
        <file>assets/code.svg</file>
        <file>assets/copy.svg</file>
        <file>assets/delete.svg</file>
        <file>assets/paste.svg</file>
        <file>assets/print.svg</file>
        <file>assets/redo.svg</file>
        <file>assets/reset.svg</file>
        <file>assets/save.svg</file>
        <file>assets/undo.svg</file>
        <file>assets/font.svg</file>
        <file>assets/clear.svg</file>
        <file>assets/settings.svg</file>
        <file>assets/open.svg</file>
        <file>assets/add-glyph.svg</file>
        <file>assets/delete-glyph.svg</file>
    </qresource>
    <qresource prefix="/icon">
        <file>assets/icon/fontedit256.png</file>
        <file>assets/icon/fontedit96.png</file>
        <file>assets/icon/fontedit96@2x.png</file>
    </qresource>
    <qresource prefix="/l10n">
        <file alias="fontedit_en.qm">l10n/fontedit_en.qm</file>
    </qresource>
</RCC>


================================================
FILE: app/cmake_uninstall.cmake.in
================================================
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
    exec_program(
      "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
      OUTPUT_VARIABLE rm_out
      RETURN_VALUE rm_retval
      )
    if(NOT "${rm_retval}" STREQUAL 0)
      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
    endif(NOT "${rm_retval}" STREQUAL 0)
  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
  endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)


================================================
FILE: app/command.h
================================================
#ifndef COMMAND_H
#define COMMAND_H

#include <QUndoCommand>
#include "facewidget.h"
#include "mainwindowmodel.h"

class Command : public QUndoCommand
{
public:
    Command(const QString& name,
            std::function<void()> undo,
            std::function<void()> redo,
            QUndoCommand *parent = nullptr) :
        QUndoCommand(name, parent),
        undo_ { undo },
        redo_ { redo }
    {}

    void undo() override { undo_(); }
    void redo() override { redo_(); }

    int id() const override { return -1; }

protected:
    std::function<void()> undo_;
    std::function<void()> redo_;
};


class SwitchActiveGlyphCommand : public QUndoCommand
{
public:
    SwitchActiveGlyphCommand(FaceWidget* faceWidget,
                             MainWindowModel* viewModel,
                             std::size_t fromIndex,
                             std::size_t toIndex,
                             QUndoCommand *parent = nullptr) :
        QUndoCommand(QObject::tr("Switch Active Glyph"), parent),
        faceWidget_ { faceWidget },
        viewModel_ { viewModel },
        fromIndex_ { fromIndex },
        toIndex_ { toIndex }
    {}

    void undo() override {
        faceWidget_->setCurrentGlyphIndex(fromIndex_);
        viewModel_->setActiveGlyphIndex(fromIndex_);
    }

    void redo() override {
        faceWidget_->setCurrentGlyphIndex(toIndex_);
        viewModel_->setActiveGlyphIndex(toIndex_);
    }

    bool isObsolete() const {
        return fromIndex_ == toIndex_;
    }

    int id() const override { return 0xa5b939e9; }

    bool mergeWith(const QUndoCommand *other) override {
        if (other->id() != id())
            return false;

        auto otherCommand = static_cast<const SwitchActiveGlyphCommand *>(other);

        toIndex_ = otherCommand->toIndex_;
        return true;
    }

    void setToIndex(std::size_t index) {
        toIndex_ = index;
    }

private:
    FaceWidget* faceWidget_;
    MainWindowModel* viewModel_;
    std::size_t fromIndex_;
    std::size_t toIndex_;
};

#endif // COMMAND_H


================================================
FILE: app/common/CMakeLists.txt
================================================
cmake_minimum_required(VERSION 3.9)

set(CMAKE_AUTOUIC OFF)
set(CMAKE_AUTOMOC OFF)
set(CMAKE_AUTORCC OFF)

project(common LANGUAGES CXX)

find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)

add_library(common
    common.h
    f2b_qt_compat.cpp
    f2b_qt_compat.h)

target_include_directories(common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(common PRIVATE Qt5::Widgets Qt5::Core font2bytes)


================================================
FILE: app/common/common.h
================================================
#ifndef COMMON_H
#define COMMON_H

#include <QRgb>

namespace Color {

static constexpr QRgb activeGlyph = 0xff000000;
static constexpr QRgb inactiveGlyph = 0xffe2e2e2;
static constexpr QRgb glyphMargin = 0xffe2e2e2;

static constexpr QRgb inactiveText = 0xffc8c8c8;

}

#if defined(Q_OS_MAC)
    static const QString consoleFontName = "Monaco";
#elif defined(Q_OS_WIN)
    static const QString consoleFontName = "Consolas";
#else
    static const QString consoleFontName = "Monaco";
#endif


#endif // COMMON_H


================================================
FILE: app/common/f2b_qt_compat.cpp
================================================
#include "f2b_qt_compat.h"

static constexpr quint32 font_glyph_magic_number = 0x92588c12;
static constexpr quint32 font_face_magic_number = 0x03f59a82;

static constexpr quint32 font_glyph_version = 1;
static constexpr quint32 font_face_version = 2;

using namespace f2b;

QDataStream& operator<<(QDataStream& s, const font::glyph& glyph)
{
    s << font_glyph_magic_number;
    s << font_glyph_version;
    s.setVersion(QDataStream::Qt_5_7);
    s << (quint32) glyph.size().width;
    s << (quint32) glyph.size().height;
    s << glyph.pixels();

    return s;
}

QDataStream& operator>>(QDataStream& s, font::glyph& glyph)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == font_glyph_magic_number && version == font_glyph_version) {
        s.setVersion(QDataStream::Qt_5_7);
        quint32 width, height;
        s >> width >> height;

        std::vector<bool> pixels;
        pixels.reserve(width * height);
        s >> pixels;

        glyph = font::glyph({width, height}, pixels);
    }

    return s;
}

QDataStream& operator<<(QDataStream& s, const font::face& face)
{
    s << font_face_magic_number;
    s << font_face_version;
    s.setVersion(QDataStream::Qt_5_7);
    s << (quint32) face.glyphs_size().width;
    s << (quint32) face.glyphs_size().height;
    s << face.glyphs();
    s << face.exported_glyph_ids();

    return s;

}

QDataStream& operator>>(QDataStream& s, font::face& face)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == font_face_magic_number) {
        s.setVersion(QDataStream::Qt_5_7);
        quint32 width, height;
        s >> width >> height;

        std::vector<font::glyph> glyphs;
        s >> glyphs;

        std::set<std::size_t> exported_glyph_ids;
        if (version < 2) {
            for (std::size_t i = 0; i < glyphs.size(); i++) {
                exported_glyph_ids.insert(i);
            }
        } else {
            s >> exported_glyph_ids;
        }
        face = font::face({width, height}, glyphs, exported_glyph_ids);
    }

    return s;
}

QVariant to_qvariant(const source_code::indentation& i) {
    if (std::holds_alternative<source_code::tab>(i)) {
        return QVariant(-1);
    } else if (std::holds_alternative<source_code::space>(i)) {
        return QVariant((uint)std::get<source_code::space>(i).num_spaces);
    }
    return QVariant();
}

source_code::indentation from_qvariant(const QVariant& v) {
    bool ok;
    auto intValue = v.toInt(&ok);
    if (ok && intValue == -1) {
        return source_code::tab {};
    }
    auto uintValue = v.toUInt(&ok);
    if (ok) {
        return source_code::space { uintValue };
    }
    return source_code::tab {};
}


================================================
FILE: app/common/f2b_qt_compat.h
================================================
#ifndef F2B_QT_COMPAT_H
#define F2B_QT_COMPAT_H

#include "f2b.h"
#include <QPoint>
#include <QSize>
#include <QBitmap>
#include <QPainter>
#include <QDebug>
#include "common.h"

#include <QDataStream>
#include <optional>
#include <vector>
#include <unordered_map>
#include <set>

namespace f2b {

namespace font {

inline font::point point_with_qpoint(const QPoint &p)
{
    return { static_cast<std::size_t>(qMax(0, p.x())),
                static_cast<std::size_t>(qMax(0, p.y())) };
}

inline QPoint qpoint_with_point(const font::point &p)
{
    return QPoint { static_cast<int>(p.x), static_cast<int>(p.y) };
}

inline font::glyph_size size_with_qsize(const QSize &s)
{
    return { static_cast<std::size_t>(qMax(0, s.width())),
                static_cast<std::size_t>(qMax(0, s.height())) };
}

inline QSize qsize_with_size(const font::glyph_size &s)
{
    return QSize { static_cast<int>(s.width), static_cast<int>(s.height) };
}

inline QImage glyph_preview_image(const font::glyph &g, font::margins m)
{
    auto useful_glyph_size = g.size();
    useful_glyph_size.height -= m.top + m.bottom;

    auto useful_image_size = qsize_with_size(useful_glyph_size);

    QImage image(useful_image_size, QImage::Format_Mono);
    image.fill(1);

    for (std::vector<bool>::size_type y = 0; y < useful_glyph_size.height; ++y) {
        for (std::vector<bool>::size_type x = 0; x < useful_glyph_size.width; ++x) {
            if (g.is_pixel_set({x, y + m.top})) {
                image.setPixel(x, y, 0);
            }
        }
    }

    return image;
}

} // namespace Font

} // namespace f2b


static constexpr quint32 std_optional_magic_number = 0x46b13680;
static constexpr quint32 std_vector_magic_number = 0x30612113;
static constexpr quint32 std_set_magic_number = 0x254c2e1e;
static constexpr quint32 std_unordered_map_magic_number = 0xc9eb6edf;

static constexpr quint32 std_optional_version = 1;
static constexpr quint32 std_vector_version = 1;
static constexpr quint32 std_set_version = 1;
static constexpr quint32 std_unordered_map_version = 1;

template<typename T>
inline QDataStream& operator<<(QDataStream& s, const std::optional<T>& opt)
{
    s << std_optional_magic_number;
    s << std_optional_version;
    s.setVersion(QDataStream::Qt_5_7);
    if (opt.has_value()) {
        s << true << QVariant(opt.value());
    } else {
        s << false;
    }
    return s;
}

template<typename T>
inline QDataStream& operator>>(QDataStream& s, std::optional<T>& opt)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == std_optional_magic_number && version == std_optional_version) {
        s.setVersion(QDataStream::Qt_5_7);
        bool has_value;
        s >> has_value;

        QVariant value;

        if (has_value) {
            s >> value;
            opt = value.value<T>();
        } else {
            opt = {};
        }
    }

    return s;
}


template<typename T>
inline QDataStream& operator<<(QDataStream& s, const std::vector<T>& vec)
{
    s << std_vector_magic_number;
    s << std_vector_version;
    s.setVersion(QDataStream::Qt_5_7);
    s << (quint32) vec.size();

    for (const auto& value : vec) {
        s << value;
    }

    return s;
}

template<typename T>
inline QDataStream& operator>>(QDataStream& s, std::vector<T>& vec)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == std_vector_magic_number && version == std_vector_version) {
        s.setVersion(QDataStream::Qt_5_7);
        quint32 size;
        s >> size;

        vec.clear();
        vec.reserve(size);

        T value;
        for (quint32 i = 0; i < size; ++i) {
            s >> value;
            vec.push_back(value);
        }
    }
    return s;
}


template<typename T>
inline QDataStream& operator<<(QDataStream& s, const std::set<T>& set)
{
    s << std_set_magic_number;
    s << std_set_version;
    s.setVersion(QDataStream::Qt_5_7);
    s << (quint32) set.size();

    for (const auto& value : set) {
        s << value;
    }

    return s;
}

template<typename T>
inline QDataStream& operator>>(QDataStream& s, std::set<T>& set)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == std_set_magic_number && version == std_set_version) {
        s.setVersion(QDataStream::Qt_5_7);
        quint32 size;
        s >> size;

        set.clear();

        T value;
        for (quint32 i = 0; i < size; ++i) {
            s >> value;
            set.insert(value);
        }
    }
    return s;
}

template<>
inline QDataStream& operator<<(QDataStream& s, const std::set<std::size_t>& set)
{
    s << std_set_magic_number;
    s << std_set_version;
    s.setVersion(QDataStream::Qt_5_7);
    s << (quint32) set.size();

    for (const auto& value : set) {
        s << (quint32) value;
    }

    return s;
}

template<>
inline QDataStream& operator>>(QDataStream& s, std::set<std::size_t>& set)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == std_set_magic_number && version == std_set_version) {
        s.setVersion(QDataStream::Qt_5_7);
        quint32 size;
        s >> size;

        set.clear();

        quint32 value;
        for (quint32 i = 0; i < size; ++i) {
            s >> value;
            set.insert(static_cast<std::size_t>(value));
        }
    }
    return s;
}


template<typename K, typename V>
inline QDataStream& operator<<(QDataStream& s, const std::unordered_map<K, V>& map)
{
    s << std_unordered_map_magic_number;
    s << std_unordered_map_version;
    s.setVersion(QDataStream::Qt_5_7);
    s << (quint32) map.size();

    for (const auto& [k,v] : map) {
        s << k;
        s << v;
    }

    return s;
}

template<typename V>
inline QDataStream& operator<<(QDataStream& s, const std::unordered_map<std::size_t, V>& map)
{
    s << std_unordered_map_magic_number;
    s << std_unordered_map_version;
    s.setVersion(QDataStream::Qt_5_7);
    s << (quint32) map.size();

    for (const auto& [k,v] : map) {
        s << (quint32) k;
        s << v;
    }

    return s;
}

template<typename K, typename V>
inline QDataStream& operator>>(QDataStream& s, std::unordered_map<K, V>& map)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == std_unordered_map_magic_number && version == std_unordered_map_version) {
        s.setVersion(QDataStream::Qt_5_7);
        quint32 size;
        s >> size;

        map.clear();
        map.reserve(size);

        K key;
        V value;
        for (quint32 i = 0; i < size; ++i) {
            s >> key;
            s >> value;
            map[key] = value;
        }
    }
    return s;
}

template<typename V>
inline QDataStream& operator>>(QDataStream& s, std::unordered_map<std::size_t, V>& map)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == std_unordered_map_magic_number && version == std_unordered_map_version) {
        s.setVersion(QDataStream::Qt_5_7);
        quint32 size;
        s >> size;

        map.clear();
        map.reserve(size);

        quint32 key;
        V value;
        for (quint32 i = 0; i < size; ++i) {
            s >> key;
            s >> value;
            map[static_cast<std::size_t>(key)] = value;
        }
    }
    return s;
}

QDataStream& operator<<(QDataStream& s, const f2b::font::glyph& glyph);
QDataStream& operator>>(QDataStream& s, f2b::font::glyph& glyph);

QDataStream& operator<<(QDataStream& s, const f2b::font::face& face);
QDataStream& operator>>(QDataStream& s, f2b::font::face& face);


QVariant to_qvariant(const f2b::source_code::indentation& i);
f2b::source_code::indentation from_qvariant(const QVariant& v);

#endif // F2B_QT_COMPAT_H


================================================
FILE: app/fontfaceviewmodel.cpp
================================================
#include "fontfaceviewmodel.h"
#include "f2b.h"
#include "f2b_qt_compat.h"
#include "qfontfacereader.h"

#include <utility>
#include <stdexcept>
#include <cassert>

#include <QDebug>
#include <QPalette>
#include <QFileInfo>


f2b::font::face import_face(const QFont &font)
{
    QFontFaceReader adapter(font);
    return f2b::font::face(adapter);
}

QString font_name(const QFont &font)
{
    QStringList s;
    s << QString("%1 %2pt").arg(font.family()).arg(QString::number(font.pointSize()));
    if (font.bold()) {
        s << "Bold";
    }
    if (font.italic()) {
        s << "Italic";
    }
    if (font.underline()) {
        s << "Underline";
    }
    if (font.strikeOut()) {
        s << "Strikeout";
    }

    return s.join(", ");
}


FontFaceViewModel::FontFaceViewModel(const QString& documentFilePath)
{
    QFile f(documentFilePath);
    if (!f.exists() || !f.permissions().testFlag(QFileDevice::ReadUser)) {
        throw std::runtime_error { "Unable to open file " + documentFilePath.toStdString() };
    }

    f.open(QIODevice::ReadOnly);
    QDataStream s(&f);
    s >> *this;
    f.close();
    isDirty_ = false;
}

FontFaceViewModel::FontFaceViewModel(f2b::font::face face, std::optional<QString> name) noexcept :
    face_ { face },
    name_ { name },
    originalMargins_ { face.calculate_margins() }
{
}

FontFaceViewModel::FontFaceViewModel(const QFont &font) :
    FontFaceViewModel(import_face(font), font_name(font))
{
    font_ = font;
    isDirty_ = true;
}

void FontFaceViewModel::saveToFile(const QString &documentPath)
{
    QFile f(documentPath);
    QFile directory(QFileInfo(documentPath).path());

    if (!directory.permissions().testFlag(QFileDevice::WriteUser) ||
            (f.exists() && !f.permissions().testFlag(QFileDevice::WriteUser)))
    {
        throw std::runtime_error { "Unable to write to file: " + documentPath.toStdString() };
    }

    f.open(QIODevice::WriteOnly);
    QDataStream s(&f);
    s << *this;
    f.close();
    isDirty_ = false;
}

FaceInfo FontFaceViewModel::faceInfo() const
{
    auto fontName = name_.has_value() ? name_.value() : QObject::tr("Custom font");
    auto size = face_.glyphs_size();
    size.height -= originalMargins_.top + originalMargins_.bottom;
    return { fontName, face_.glyphs_size(), size, face_.num_glyphs(), face_.exported_glyph_ids().size() };
}

void FontFaceViewModel::modifyGlyph(std::size_t index, const f2b::font::glyph &new_glyph)
{
    doModifyGlyph(index, [&](f2b::font::glyph &glyph) {
        glyph = new_glyph;
    });
}

void FontFaceViewModel::modifyGlyph(std::size_t index,
                                     const BatchPixelChange &change,
                                     BatchPixelChange::ChangeType changeType)
{
    doModifyGlyph(index, [&](f2b::font::glyph& glyph) {
        change.apply(glyph, changeType);
    });
}

void FontFaceViewModel::doModifyGlyph(std::size_t idx, std::function<void (f2b::font::glyph&)> change)
{
    f2b::font::glyph& glyph { face_.glyph_at(idx) };
    bool first_change = false;

    if (originalGlyphs_.count(idx) == 0) {
        qDebug() << "active_glyph non-const cache miss";
        originalGlyphs_.insert({ idx, glyph });
        first_change = true;
    } else {
        qDebug() << "active_glyph non-const cache hit";
    }

    change(glyph);
    isDirty_ = true;

    // remove glyph from originals when restoring initial state
    if (!first_change && glyph == originalGlyphs_.at(idx)) {
        originalGlyphs_.erase(idx);
    }
}

void FontFaceViewModel::reset()
{
    face_ = originalFace();
    originalGlyphs_.clear();
}

void FontFaceViewModel::resetGlyph(std::size_t index)
{
    if (isGlyphModified(index)) {
        face_.set_glyph(originalGlyphs_.at(index), index);
        originalGlyphs_.erase(activeGlyphIndex_.value());
        isDirty_ = true;
    }
}

void FontFaceViewModel::appendGlyph(f2b::font::glyph newGlyph)
{
    face_.append_glyph(std::move(newGlyph));
    isDirty_ = true;
}

void FontFaceViewModel::deleteGlyph(std::size_t index)
{
    if (index == face_.num_glyphs() - 1) {
        if (activeGlyphIndex_.has_value() && activeGlyphIndex_.value() == face_.num_glyphs() - 1) {
            activeGlyphIndex_ = face_.num_glyphs() - 2;
        }
        face_.delete_last_glyph();
    } else {
        face_.clear_glyph(index);
    }
    isDirty_ = true;
}

f2b::font::face FontFaceViewModel::originalFace() const noexcept
{
    f2b::font::face f = face_;
    for (const auto& pair : originalGlyphs_) {
        f.set_glyph(pair.second, pair.first);
    }
    return f;
}

static constexpr auto fontfaceviewmodel_magic_number = 0x1c22f998;
static constexpr auto fontfaceviewmodel_version = 2;

QDataStream& operator<<(QDataStream& s, const FontFaceViewModel &vm)
{
    s << (quint32) fontfaceviewmodel_magic_number;
    s << (qint32) fontfaceviewmodel_version;
    s.setVersion(QDataStream::Qt_5_7);

    s << vm.face_;
    s << vm.name_;
    s << (quint32) vm.originalMargins_.top << (quint32) vm.originalMargins_.bottom;

    s << vm.font_;
    return s;
}

QDataStream& operator>>(QDataStream& s, FontFaceViewModel& vm)
{
    quint32 magic_number;
    quint32 version;
    s >> magic_number >> version;
    if (magic_number == fontfaceviewmodel_magic_number && version <= fontfaceviewmodel_version) {
        s.setVersion(QDataStream::Qt_5_7);

        s >> vm.face_;
        s >> vm.name_;

        quint32 top, bottom;
        s >> top >> bottom;
        vm.originalMargins_ = { top, bottom };
        vm.originalGlyphs_ = {};
        vm.activeGlyphIndex_ = {};

        if (version <= 2) {
            s >> vm.font_;
        }
    }

    return s;
}


================================================
FILE: app/fontfaceviewmodel.h
================================================
#ifndef FONTFACEVIEWMODEL_H
#define FONTFACEVIEWMODEL_H

#include <QFont>
#include "f2b.h"
#include <optional>
#include <vector>
#include <exception>
#include <unordered_map>
#include "batchpixelchange.h"

struct FaceInfo
{
    QString fontName;
    f2b::font::glyph_size size;
    f2b::font::glyph_size sizeWithoutMargins;
    std::size_t numberOfGlyphs;
    std::size_t numberOfExportedGlyphs;
};

class FontFaceViewModel
{
public:
    explicit FontFaceViewModel() = default;
    explicit FontFaceViewModel(const QString& documentPath);
    explicit FontFaceViewModel(f2b::font::face face, std::optional<QString> name) noexcept;
    explicit FontFaceViewModel(const QFont& font);

    void saveToFile(const QString& documentPath);

    std::optional<QFont> font() const noexcept { return font_; }

    const f2b::font::face& face() const noexcept { return face_; }
    f2b::font::face& face() noexcept { return face_; }

    FaceInfo faceInfo() const;

    f2b::font::face originalFace() const noexcept;
    f2b::font::margins originalFaceMargins() const noexcept { return originalMargins_; }

    void setGlyphExportedState(std::size_t idx, bool isExported) {
        if (idx >= face_.num_glyphs()) {
            throw std::out_of_range("Active glyph index higher than number of glyphs.");
        }
        if (isExported) {
            face_.exported_glyph_ids().insert(idx);
        } else {
            face_.exported_glyph_ids().erase(idx);
        }
        isDirty_ = true;
    }

    void setActiveGlyphIndex(std::optional<std::size_t> idx) {
        if (idx.has_value() && idx.value() >= face_.num_glyphs()) {
            throw std::out_of_range("Active glyph index higher than number of glyphs.");
        }
        activeGlyphIndex_ = idx;
    }

    std::optional<std::size_t> activeGlyphIndex() const noexcept {
        return activeGlyphIndex_;
    }

    std::optional<f2b::font::glyph> activeGlyph() const {
        if (activeGlyphIndex_.has_value()) {
            return face_.glyph_at(activeGlyphIndex_.value());
        }
        return {};
    }

    void resetActiveGlyph() {
        if (!activeGlyphIndex_.has_value()) {
            return;
        }
        resetGlyph(activeGlyphIndex_.value());
    }

    void reset();

    void resetGlyph(std::size_t index);
    void modifyGlyph(std::size_t index, const f2b::font::glyph& new_glyph);
    void modifyGlyph(std::size_t index, const BatchPixelChange& change,
                      BatchPixelChange::ChangeType changeType = BatchPixelChange::ChangeType::Normal);
    void appendGlyph(f2b::font::glyph newGlyph);
    void deleteGlyph(std::size_t index);

    bool isModified() const {
        return originalGlyphs_.size() > 0;
    }

    bool isGlyphModified(std::size_t idx) const {
        // modified glyphs have their unmodified counterparts stored in originalGlyphs_.
        return originalGlyphs_.count(idx) == 1;
    }

    bool isModifiedSinceSave() const {
        return isDirty_;
    }

private:
    void doModifyGlyph(std::size_t idx, std::function<void(f2b::font::glyph&)> change);

    f2b::font::face face_;
    std::optional<QString> name_;
    f2b::font::margins originalMargins_;
    // this holds copies of unmodified glyphs once they are edited.
    std::unordered_map<std::size_t, f2b::font::glyph> originalGlyphs_;
    std::optional<QFont> font_;

    // not persisted
    std::optional<std::size_t> activeGlyphIndex_;
    bool isDirty_ { false };

    friend QDataStream& operator<<(QDataStream&, const FontFaceViewModel&);
    friend QDataStream& operator>>(QDataStream& s, FontFaceViewModel& vm);
};

QDataStream& operator<<(QDataStream& s, const FontFaceViewModel& vm);
QDataStream& operator>>(QDataStream& s, FontFaceViewModel& vm);

#endif // FONTFACEVIEWMODEL_H


================================================
FILE: app/global.h
================================================
#ifndef GLOBAL_H
#define GLOBAL_H

#include <QString>

namespace Global {
static const QString organization_name = "Dominik Kapusta";
static const QString organization_domain = "kapusta.cc";
static const QString application_name = "FontEdit";
static constexpr std::string_view application_version = VERSION;
}


#endif // GLOBAL_H


================================================
FILE: app/l10n/fontedit_en.ts
================================================
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
    <name>AboutDialog</name>
    <message>
        <location filename="../ui/aboutdialog.ui" line="14"/>
        <source>About FontEdit</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../ui/aboutdialog.ui" line="75"/>
        <source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:18pt;&quot;&gt;FontEdit &lt;/span&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt;v##version## build ##build##&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt;Copyright ##year## Dominik Kapusta&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;https://github.com/ayoy/fontedit&quot;&gt;&lt;span style=&quot; font-size:13pt; font-weight:400; text-decoration: underline; color:#0068da;&quot;&gt;Get Source Code&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt;•&lt;/span&gt;&lt;a href=&quot;https://github.com/ayoy/fontedit/issues&quot;&gt;&lt;span style=&quot; font-size:13pt; font-weight:400; text-decoration: underline; color:#0068da;&quot;&gt;Report a Bug&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt;This program is distributed under the terms of &lt;/span&gt;&lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.en.html&quot;&gt;&lt;span style=&quot; font-size:13pt; font-weight:400; text-decoration: underline; color:#0068da;&quot;&gt;General Public License v3&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:13pt;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt;&lt;br/&gt;Icons made by &lt;/span&gt;&lt;a href=&quot;https://www.flaticon.com/authors/smashicons&quot;&gt;&lt;span style=&quot; font-size:13pt; font-weight:400; text-decoration: underline; color:#0068da;&quot;&gt;Smashicons&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt; and &lt;/span&gt;&lt;a href=&quot;https://www.flaticon.com/authors/freepik&quot;&gt;&lt;span style=&quot; font-size:13pt; font-weight:400; text-decoration: underline; color:#0068da;&quot;&gt;Freepik&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt; from &lt;/span&gt;&lt;a href=&quot;https://www.flaticon.com/&quot;&gt;&lt;span style=&quot; font-size:13pt; font-weight:400; text-decoration: underline; color:#0068da;&quot;&gt;www.flaticon.com&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:13pt; font-weight:400;&quot;&gt;.&lt;/span&gt;&lt;a href=&quot;https://www.flaticon.com/&quot;&gt;&lt;span style=&quot; font-size:13pt; font-weight:400; text-decoration: underline; color:#0068da;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
        <translation></translation>
    </message>
</context>
<context>
    <name>AddGlyphDialog</name>
    <message>
        <location filename="../addglyphdialog.ui" line="20"/>
        <source>Add New Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../addglyphdialog.ui" line="29"/>
        <source>Adding Glyph for </source>
        <translation></translation>
    </message>
    <message>
        <location filename="../addglyphdialog.ui" line="38"/>
        <source>Add empty Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../addglyphdialog.ui" line="55"/>
        <source>Initialize with font character:</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../addglyphdialog.ui" line="65"/>
        <source>Current document font not found in system</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../addglyphdialog.ui" line="78"/>
        <source>Type character here</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../addglyphdialog.ui" line="102"/>
        <source>Copy existing Glyph:</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../addglyphdialog.cpp" line="15"/>
        <source>Add a new Glyph to %1</source>
        <translation></translation>
    </message>
</context>
<context>
    <name>GlyphInfoWidget</name>
    <message>
        <location filename="../ui/glyphinfowidget.cpp" line="34"/>
        <source>Exported</source>
        <translation></translation>
    </message>
</context>
<context>
    <name>MainWindow</name>
    <message>
        <location filename="../mainwindow.ui" line="32"/>
        <source>Edit Font</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="72"/>
        <source>Ctrl+R</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="266"/>
        <source>TextLabel</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="298"/>
        <source>Source Code</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="334"/>
        <source>Updating source code...</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="350"/>
        <source>Output Format</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="388"/>
        <source>Misc Options</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="394"/>
        <source>Invert Bits</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="401"/>
        <source>Reverse Bits (MSB)</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="465"/>
        <source>Print</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="14"/>
        <source>FontEdit</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="240"/>
        <source>Toggle exported state by pressing Space on a selected glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="243"/>
        <location filename="../mainwindow.ui" line="702"/>
        <source>Show non-exported Glyphs</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="359"/>
        <source>Export Selected Glyphs</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="369"/>
        <source>Export All Glyphs</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="408"/>
        <source>Include Line Spacing</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="418"/>
        <source>Font Array Name</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="430"/>
        <source>font</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="440"/>
        <source>Indentation</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="472"/>
        <source>Export Source Code...</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="495"/>
        <source>File</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="511"/>
        <source>Edit</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="524"/>
        <source>Help</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="531"/>
        <source>View</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="543"/>
        <source>New</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="546"/>
        <location filename="../mainwindow.ui" line="558"/>
        <source>Ctrl+N</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="555"/>
        <source>Import Font</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="567"/>
        <location filename="../mainwindow.cpp" line="668"/>
        <source>Reset Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="576"/>
        <source>Export...</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="585"/>
        <location filename="../mainwindow.cpp" line="492"/>
        <source>Save</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="588"/>
        <source>Ctrl+S</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="597"/>
        <location filename="../mainwindow.cpp" line="684"/>
        <source>Reset Font</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="606"/>
        <source>Print...</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="609"/>
        <source>Ctrl+P</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="614"/>
        <source>Save As...</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="617"/>
        <source>Ctrl+Shift+S</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="626"/>
        <location filename="../mainwindow.cpp" line="397"/>
        <source>Add Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="629"/>
        <source>Ctrl+Shift+N</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="634"/>
        <source>Quit</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="637"/>
        <source>Ctrl+Q</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="646"/>
        <source>Copy Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="655"/>
        <source>Paste Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="664"/>
        <source>Open...</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="667"/>
        <source>Ctrl+O</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="672"/>
        <source>Recent files</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="677"/>
        <source>Close</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="682"/>
        <source>About FontEdit</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="691"/>
        <location filename="../mainwindow.cpp" line="415"/>
        <location filename="../mainwindow.cpp" line="425"/>
        <source>Delete Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.ui" line="707"/>
        <source>Check for Updates...</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="204"/>
        <source>Check for updates at start-up</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="213"/>
        <source>Update Available</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="214"/>
        <source>FontEdit %1 is available (you have %2).
Get the new version from GitHub Releases Page.</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="218"/>
        <source>Go to Releases Page</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="219"/>
        <source>Dismiss</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="228"/>
        <source>No Update Available</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="229"/>
        <source>You&apos;re using the latest version of FontEdit</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="300"/>
        <source>Start by importing a system font or opening an existing document</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="303"/>
        <source>Select a glyph on the right to edit it</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="306"/>
        <source>Click and drag to paint, hold Alt or Ctrl to erase.</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="347"/>
        <source>Select Font</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="366"/>
        <source>Open Document</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="416"/>
        <source>You can only delete Glyphs at the end of the list. This Glyph will be cleared instead of deleted (to ensure that other Glyphs&apos; indexes are unchanged).</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="425"/>
        <source>Clear Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="462"/>
        <source>Save Document</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="470"/>
        <source>Error</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="492"/>
        <source>Don&apos;t Save</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="492"/>
        <source>Cancel</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="495"/>
        <source>Do you want to save the changes you made? Your changes will be lost if you don&apos;t save them.</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="543"/>
        <source>Toggle Glyph Exported</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="589"/>
        <source>Size (full): %1x%2px</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="590"/>
        <source>Size (adjusted): %1x%2px</source>
        <translation></translation>
    </message>
    <message numerus="yes">
        <location filename="../mainwindow.cpp" line="591"/>
        <source>%n Glyph(s)</source>
        <translation>
            <numerusform>%n Glyph</numerusform>
            <numerusform>%n Glyphs</numerusform>
        </translation>
    </message>
    <message numerus="yes">
        <location filename="../mainwindow.cpp" line="592"/>
        <source>%n to export</source>
        <translation>
            <numerusform>%n to export</numerusform>
            <numerusform>%n to export</numerusform>
        </translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="635"/>
        <source>Edit Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="683"/>
        <source>Are you sure you want to reset all changes to the font? This operation cannot be undone.</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="746"/>
        <source>Save Source Code</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="761"/>
        <source>Source code successfully exported.</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindow.cpp" line="763"/>
        <source>Unable to write to file: </source>
        <translation></translation>
    </message>
</context>
<context>
    <name>MainWindowModel</name>
    <message>
        <location filename="../mainwindowmodel.cpp" line="68"/>
        <source>Tab</source>
        <translation></translation>
    </message>
    <message numerus="yes">
        <location filename="../mainwindowmodel.cpp" line="70"/>
        <source>%n Space(s)</source>
        <translation>
            <numerusform>%n Space</numerusform>
            <numerusform>%n Spaces</numerusform>
        </translation>
    </message>
    <message>
        <location filename="../mainwindowmodel.cpp" line="145"/>
        <source>New Document</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../mainwindowmodel.cpp" line="151"/>
        <source>Edited</source>
        <translation></translation>
    </message>
</context>
<context>
    <name>QObject</name>
    <message>
        <location filename="../command.h" line="39"/>
        <source>Switch Active Glyph</source>
        <translation></translation>
    </message>
    <message>
        <location filename="../fontfaceviewmodel.cpp" line="90"/>
        <source>Custom font</source>
        <translation></translation>
    </message>
</context>
</TS>


================================================
FILE: app/macos/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleExecutable</key>
	<string>FontEdit</string>
	<key>CFBundleGetInfoString</key>
	<string></string>
	<key>CFBundleIconFile</key>
	<string>fontedit.icns</string>
	<key>CFBundleIdentifier</key>
	<string>cc.kapusta.FontEdit</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleLongVersionString</key>
	<string></string>
	<key>CFBundleName</key>
	<string></string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
    <string>1.1.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
    <string>4</string>
	<key>CSResourcesFileMapped</key>
	<true/>
    <key>LSMinimumSystemVersion</key>
    <string>10.14</string>
	<key>NSHumanReadableCopyright</key>
	<string></string>
	<key>NSPrincipalClass</key>
	<string>NSApplication</string>
	<key>NSHighResolutionCapable</key>
	<string>True</string>
    <key>NSRequiresAquaSystemAppearance</key>
    <true/>
</dict>
</plist>


================================================
FILE: app/main.cpp
================================================
#include "mainwindow.h"
#include "global.h"

#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QApplication::setOrganizationName(Global::organization_name);
    QApplication::setOrganizationDomain(Global::organization_domain);
    QApplication::setApplicationName(Global::application_name);
    QApplication::setApplicationVersion(QString::fromStdString(std::string(Global::application_version)));

    QTranslator myappTranslator;
    myappTranslator.load(":/l10n/fontedit_en.qm");
    a.installTranslator(&myappTranslator);

    a.setAttribute(Qt::AA_UseHighDpiPixmaps);

    MainWindow w;
    w.show();
    return QApplication::exec();
}


================================================
FILE: app/mainwindow.cpp
================================================
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "f2b.h"
#include "facewidget.h"
#include "fontfaceviewmodel.h"
#include "command.h"
#include "aboutdialog.h"
#include "addglyphdialog.h"
#include "common.h"

#include <QGraphicsGridLayout>
#include <QGraphicsWidget>
#include <QDebug>
#include <QStyle>
#include <QFontDialog>
#include <QFileDialog>
#include <QScrollBar>
#include <QMessageBox>
#include <QKeySequence>
#include <QElapsedTimer>
#include <QStandardPaths>
#include <QDesktopServices>

#include <iostream>
#include <stdexcept>

#include <QFile>
#include <QTextStream>

static constexpr auto codeTabIndex = 1;
static constexpr auto exportAllButtonIndex = -3;
static constexpr auto fileFilter = "FontEdit documents (*.fontedit)";

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
      ui_ { new Ui::MainWindow },
      statusLabel_ { new QLabel() }
{
    ui_->setupUi(this);

    initUI();
    setupActions();
    updateUI(viewModel_->uiState());

    connectUpdateHelper();
    connectUIInputs();
    connectViewModelOutputs();
    viewModel_->restoreSession();

    ui_->statusBar->addPermanentWidget(statusLabel_);

    updateHelper_->checkForUpdatesIfNeeded();
}

MainWindow::~MainWindow()
{
    delete ui_;
}

void MainWindow::connectUpdateHelper()
{
    connect(updateHelper_.get(), &UpdateHelper::updateAvailable,
            [&] (UpdateHelper::Update update) {
        showUpdateDialog(update);
    });
    connect(updateHelper_.get(), &UpdateHelper::updateNotAvailable,
            [&] {
        showUpdateDialog({});
    });
}

void MainWindow::connectUIInputs()
{
    connect(ui_->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog);
    connect(ui_->actionImport_Font, &QAction::triggered, this, &MainWindow::showFontDialog);
    connect(ui_->actionOpen, &QAction::triggered, this, &MainWindow::showOpenDocumentDialog);
    connect(ui_->actionAdd_Glyph, &QAction::triggered, this, &MainWindow::showAddGlyphDialog);
    connect(ui_->actionDelete_Glyph, &QAction::triggered, this, &MainWindow::showDeleteGlyphDialog);
    connect(ui_->actionReset_Glyph, &QAction::triggered, this, &MainWindow::resetCurrentGlyph);
    connect(ui_->actionReset_Font, &QAction::triggered, this, &MainWindow::resetFont);

    connect(ui_->actionSave, &QAction::triggered, this, &MainWindow::save);
    connect(ui_->actionSave_As, &QAction::triggered, this, &MainWindow::saveAs);
    connect(ui_->actionClose, &QAction::triggered, this, &MainWindow::showCloseDocumentDialogIfNeeded);

    connect(ui_->actionExport, &QAction::triggered, this, &MainWindow::exportSourceCode);
    connect(ui_->exportButton, &QPushButton::clicked, this, &MainWindow::exportSourceCode);

    connect(ui_->actionQuit, &QAction::triggered, this, &MainWindow::close);
    connect(ui_->tabWidget, &QTabWidget::currentChanged, [&](int index) {
        if (index == codeTabIndex) {
            displaySourceCode();
            viewModel_->registerInputEvent(UIState::InterfaceAction::ActionTabCode);
        } else {
            viewModel_->registerInputEvent(UIState::InterfaceAction::ActionTabEdit);
        }
    });
    connect(ui_->exportMethodButtonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), [&](int buttonID) {
        viewModel_->setExportAllEnabled(buttonID == exportAllButtonIndex);
    });
    connect(ui_->invertBitsCheckBox, &QCheckBox::stateChanged, [&](int state) {
        viewModel_->setInvertBits(state == Qt::Checked);
    });
    connect(ui_->bitNumberingCheckBox, &QCheckBox::stateChanged, [&](int state) {
        viewModel_->setMSBEnabled(state == Qt::Checked);
    });
    connect(ui_->lineSpacingCheckBox, &QCheckBox::stateChanged, [&](int state) {
        viewModel_->setIncludeLineSpacing(state == Qt::Checked);
    });
    connect(ui_->formatComboBox, &QComboBox::currentTextChanged,
            viewModel_.get(), &MainWindowModel::setOutputFormat);
    connect(ui_->indentationComboBox, &QComboBox::currentTextChanged,
            viewModel_.get(), &MainWindowModel::setIndentation);
    connect(ui_->fontArrayNameEdit, &QLineEdit::textChanged, [&](const QString& fontArrayName) {
        auto fontName = fontArrayName.isEmpty() ? ui_->fontArrayNameEdit->placeholderText() : std::move(fontArrayName);
        debounceFontNameChanged(fontName);
    });

    connect(ui_->actionCheck_for_Updates, &QAction::triggered, [&] {
        updateHelper_->checkForUpdates(true);
    });
}

void MainWindow::connectViewModelOutputs()
{
    connect(viewModel_.get(), &MainWindowModel::documentTitleChanged, [&](const QString& title) {
        setWindowTitle(QString("FontEdit (%1)").arg(title));
    });
    connect(viewModel_.get(), &MainWindowModel::uiStateChanged, this, &MainWindow::updateUI);
    connect(viewModel_.get(), &MainWindowModel::faceLoaded, [&](f2b::font::face& face) {
        undoStack_->clear();
        displayFace(face);
    });
    connect(viewModel_.get(), &MainWindowModel::documentError, this, &MainWindow::displayError);
    connect(viewModel_.get(), &MainWindowModel::activeGlyphChanged, [&](std::optional<f2b::font::glyph> glyph) {
        if (glyph.has_value()) {
            displayGlyph(glyph.value());
        } else if (auto g = glyphWidget_.get()) {
            ui_->glyphGraphicsView->scene()->removeItem(g);
            glyphWidget_.release();
        }
    });
    connect(viewModel_.get(), &MainWindowModel::sourceCodeUpdating, [&]() {
//        ui_->stackedWidget->setCurrentWidget(ui_->spinnerContainer);
    });
    connect(viewModel_.get(), &MainWindowModel::sourceCodeChanged, [&]() {
        if (ui_->tabWidget->currentIndex() == codeTabIndex) {
            displaySourceCode();
        }
    });
    connect(viewModel_.get(), &MainWindowModel::documentClosed, this, &MainWindow::closeCurrentDocument);
}

void MainWindow::initUI()
{
    // hide not implemented UI
    ui_->actionCopy_Glyph->setVisible(false);
    ui_->actionPaste_Glyph->setVisible(false);
    ui_->copyButton->setVisible(false);
    ui_->pasteButton->setVisible(false);
    ui_->printButton->setVisible(false);
    ui_->actionPrint->setVisible(false);
    ui_->actionNew->setVisible(false);

    faceScene_->setBackgroundBrush(QBrush(Qt::lightGray));
    ui_->faceGraphicsView->setScene(faceScene_.get());

    ui_->actionShow_non_exported_Glyphs->setChecked(viewModel_->shouldShowNonExportedGlyphs());
    ui_->showNonExportedGlyphsCheckBox->setCheckState(viewModel_->shouldShowNonExportedGlyphs());

    ui_->showNonExportedGlyphsCheckBox->setVisible(false);
    ui_->faceInfoSeparator->setVisible(false);
    ui_->faceInfoLabel->setVisible(false);

    auto scrollBarWidth = ui_->faceGraphicsView->verticalScrollBar()->sizeHint().width();
    auto faceViewWidth = static_cast<int>(FaceWidget::cell_width) * 3 + scrollBarWidth;
    ui_->faceGraphicsView->setMinimumSize({ faceViewWidth,
                                            ui_->faceGraphicsView->minimumSize().height() });

    ui_->exportAllButton->setChecked(viewModel_->exportAllEnabled());
    ui_->exportSubsetButton->setChecked(!viewModel_->exportAllEnabled());
    ui_->invertBitsCheckBox->setCheckState(viewModel_->invertBits());
    ui_->bitNumberingCheckBox->setCheckState(viewModel_->msbEnabled());
    ui_->lineSpacingCheckBox->setCheckState(viewModel_->includeLineSpacing());

    for (const auto& [identifier, name] : viewModel_->outputFormats().toStdMap()) {
        ui_->formatComboBox->addItem(name, identifier);
    }
    for (const auto& [indent, name] : viewModel_->indentationStyles()) {
        ui_->indentationComboBox->addItem(name);
    }

    ui_->formatComboBox->setCurrentText(viewModel_->outputFormat());
    ui_->indentationComboBox->setCurrentText(viewModel_->indentationStyleCaption());

    QFont f(consoleFontName, 12);
    f.setStyleHint(QFont::TypeWriter);
    ui_->sourceCodeTextBrowser->setFont(f);
}

void MainWindow::showUpdateDialog(std::optional<UpdateHelper::Update> update)
{
    QMessageBox messageBox;
    messageBox.setCheckBox(new QCheckBox(tr("Check for updates at start-up")));
    messageBox.checkBox()->setChecked(updateHelper_->shouldCheckAtStartup());

    connect(messageBox.checkBox(), &QCheckBox::toggled, [&] (bool isChecked) {
        updateHelper_->setShouldCheckAtStartup(isChecked);
    });

    if (update.has_value()) {
        auto updateInfo = update.value();
        messageBox.setText(tr("Update Available"));
        messageBox.setInformativeText(tr("FontEdit %1 is available (you have %2).\nGet the new version from GitHub Releases Page.")
                                      .arg(updateInfo.latestVersion, updateInfo.currentVersion));
        messageBox.setDetailedText(updateInfo.releaseNotes);

        auto visitPageButton = messageBox.addButton(tr("Go to Releases Page"), QMessageBox::YesRole);
        messageBox.addButton(tr("Dismiss"), QMessageBox::NoRole);

        messageBox.setDefaultButton(visitPageButton);
        messageBox.exec();

        if (messageBox.clickedButton() == visitPageButton) {
            QDesktopServices::openUrl(updateInfo.webpageURL);
        }
    } else {
        messageBox.setText(tr("No Update Available"));
        messageBox.setInformativeText(tr("You're using the latest version of FontEdit"));

        messageBox.exec();
    }

}

void MainWindow::closeCurrentDocument()
{
    ui_->showNonExportedGlyphsCheckBox->setVisible(false);
    ui_->faceInfoSeparator->setVisible(false);
    ui_->faceInfoLabel->setVisible(false);

    if (faceWidget_ != nullptr) {
        faceScene_->removeItem(faceWidget_);
        delete faceWidget_;
        faceWidget_ = nullptr;
    }

    if (auto g = glyphWidget_.get()) {
        ui_->glyphGraphicsView->scene()->removeItem(g);
        glyphWidget_.release();
    }

    undoStack_->clear();
    updateResetActions();
}

void MainWindow::setupActions()
{
    auto undo = undoStack_->createUndoAction(this);
    undo->setIcon(QIcon {":/toolbar/assets/undo.svg"});
    undo->setShortcut(QKeySequence::Undo);

    auto redo = undoStack_->createRedoAction(this);
    redo->setIcon(QIcon {":/toolbar/assets/redo.svg"});
    redo->setShortcut(QKeySequence::Redo);

    ui_->openButton->setDefaultAction(ui_->actionOpen);
    ui_->importFontButton->setDefaultAction(ui_->actionImport_Font);
    ui_->addGlyphButton->setDefaultAction(ui_->actionAdd_Glyph);
    ui_->deleteGlyphButton->setDefaultAction(ui_->actionDelete_Glyph);
    ui_->saveButton->setDefaultAction(ui_->actionSave);
    ui_->copyButton->setDefaultAction(ui_->actionCopy_Glyph);
    ui_->pasteButton->setDefaultAction(ui_->actionPaste_Glyph);
    ui_->undoButton->setDefaultAction(undo);
    ui_->redoButton->setDefaultAction(redo);
    ui_->resetGlyphButton->setDefaultAction(ui_->actionReset_Glyph);
    ui_->resetFontButton->setDefaultAction(ui_->actionReset_Font);
    ui_->actionReset_Glyph->setEnabled(false);
    ui_->actionReset_Font->setEnabled(false);

    ui_->menuEdit->insertAction(ui_->actionCopy_Glyph, undo);
    ui_->menuEdit->insertAction(ui_->actionCopy_Glyph, redo);
}

void MainWindow::updateUI(UIState uiState)
{
    ui_->tabWidget->setTabEnabled(1, uiState.actions[UIState::InterfaceAction::ActionTabCode]);
    ui_->actionAdd_Glyph->setEnabled(uiState.actions[UIState::InterfaceAction::ActionAddGlyph]);
    ui_->actionDelete_Glyph->setEnabled(uiState.actions[UIState::InterfaceAction::ActionDeleteGlyph]);
    ui_->actionSave->setEnabled(uiState.actions[UIState::InterfaceAction::ActionSave]);
    ui_->actionSave_As->setEnabled(uiState.actions[UIState::InterfaceAction::ActionSave]);
    ui_->actionClose->setEnabled(uiState.actions[UIState::InterfaceAction::ActionClose]);
    ui_->actionCopy_Glyph->setEnabled(uiState.actions[UIState::InterfaceAction::ActionCopy]);
    ui_->actionPaste_Glyph->setEnabled(uiState.actions[UIState::InterfaceAction::ActionPaste]);
    ui_->actionExport->setEnabled(uiState.actions[UIState::InterfaceAction::ActionExport]);
    ui_->actionPrint->setEnabled(uiState.actions[UIState::InterfaceAction::ActionPrint]);

    switch (uiState.statusBarMessage) {
    case UIState::MessageIdle:
        statusLabel_->setText(tr("Start by importing a system font or opening an existing document"));
        break;
    case UIState::MessageLoadedFace:
        statusLabel_->setText(tr("Select a glyph on the right to edit it"));
        break;
    case UIState::MessageLoadedGlyph:
        statusLabel_->setText(tr("Click and drag to paint, hold Alt or Ctrl to erase."));
        break;
    }

    if (ui_->tabWidget->currentIndex() == codeTabIndex) {
        statusLabel_->setVisible(false);
    } else {
        statusLabel_->setVisible(true);
    }
    ui_->statusBar->clearMessage();
}

QString MainWindow::defaultDialogDirectory() const
{
    QString directoryPath = viewModel_->lastVisitedDirectory();
    if (directoryPath.isNull()) {
        directoryPath = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).last();
    }
    return directoryPath;
}

void MainWindow::showAboutDialog()
{
    auto about = new AboutDialog(this);
    about->show();
}

void MainWindow::showFontDialog()
{
    switch (promptToSaveDirtyDocument()) {
    case Save:
        save();
    case DontSave:
        break;
    case Cancel:
        return;
    }

    bool ok;
    QFont f(consoleFontName, 24);
    f.setStyleHint(QFont::TypeWriter);
    f = QFontDialog::getFont(&ok, f, this, tr("Select Font"), QFontDialog::MonospacedFonts | QFontDialog::DontUseNativeDialog);

    if (ok) {
        qDebug() << "selected font:" << f;
        viewModel_->importFont(f);
    }
}

void MainWindow::showOpenDocumentDialog()
{
    switch (promptToSaveDirtyDocument()) {
    case Save:
        save();
    case DontSave:
        break;
    case Cancel:
        return;
    }

    QString fileName = QFileDialog::getOpenFileName(this, tr("Open Document"), std::move(defaultDialogDirectory()), tr(fileFilter));

    if (!fileName.isNull())
        viewModel_->openDocument(fileName);
}

void MainWindow::showCloseDocumentDialogIfNeeded()
{
    switch (promptToSaveDirtyDocument()) {
    case Save:
        save();
    case DontSave:
        break;
    case Cancel:
        return;
    }

    viewModel_->closeCurrentDocument();
}

void MainWindow::showAddGlyphDialog()
{
    auto addGlyph = new AddGlyphDialog(*viewModel_->faceModel(), this);
    addGlyph->show();

    connect(addGlyph, &AddGlyphDialog::glyphSelected, [&](const std::optional<f2b::font::glyph>& glyph) {
        if (glyph.has_value()) {

            auto numberOfGlyphs = viewModel_->faceModel()->face().num_glyphs();
            auto activeGlyphIndex = viewModel_->faceModel()->activeGlyphIndex();

            pushUndoCommand(new Command(tr("Add Glyph"), [&, numberOfGlyphs, activeGlyphIndex] {
                viewModel_->deleteGlyph(numberOfGlyphs);
                viewModel_->setActiveGlyphIndex(activeGlyphIndex);
                displayFace(viewModel_->faceModel()->face());
            }, [&, glyph] {
                viewModel_->appendGlyph(glyph.value());
                viewModel_->setActiveGlyphIndex(viewModel_->faceModel()->face().num_glyphs()-1);
                displayFace(viewModel_->faceModel()->face());
            }));
        }
    });
}

void MainWindow::showDeleteGlyphDialog()
{
    auto currentIndex = viewModel_->faceModel()->activeGlyphIndex();
    auto isLastGlyph = currentIndex.value() == viewModel_->faceModel()->face().num_glyphs() - 1;
    if (!isLastGlyph) {
        QMessageBox::information(this, tr("Delete Glyph"),
                                 tr("You can only delete Glyphs at the end of the list. "
                                    "This Glyph will be cleared instead of deleted "
                                    "(to ensure that other Glyphs' indexes are unchanged)."),
                                 QMessageBox::StandardButton::Ok);
    }

    auto glyph = viewModel_->faceModel()->activeGlyph();
    if (glyph.has_value()) {

        auto commandName = isLastGlyph ? tr("Delete Glyph") : tr("Clear Glyph");

        pushUndoCommand(new Command(commandName, [&, currentIndex, isLastGlyph, glyph] {
            if (isLastGlyph) {
                viewModel_->appendGlyph(glyph.value());
                viewModel_->setActiveGlyphIndex(viewModel_->faceModel()->face().num_glyphs()-1);
                displayFace(viewModel_->faceModel()->face());
            } else {
                viewModel_->modifyGlyph(currentIndex.value(), glyph.value());
                faceWidget_->updateGlyphInfo(currentIndex.value(), viewModel_->faceModel()->activeGlyph().value());
                displayGlyph(viewModel_->faceModel()->activeGlyph().value());
            }
        }, [&, currentIndex, isLastGlyph] {
            viewModel_->deleteGlyph(currentIndex.value());
            if (isLastGlyph) {
                displayFace(viewModel_->faceModel()->face());
            } else {
                faceWidget_->updateGlyphInfo(currentIndex.value(), viewModel_->faceModel()->activeGlyph().value());
                displayGlyph(viewModel_->faceModel()->activeGlyph().value());
            }
        }));

    }
}

void MainWindow::save()
{
    auto currentPath = viewModel_->currentDocumentPath();
    if (currentPath.has_value()) {
        viewModel_->saveDocument(currentPath.value());
    } else {
        saveAs();
    }
}

void MainWindow::saveAs()
{
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save Document"), std::move(defaultDialogDirectory()), tr(fileFilter));

    if (!fileName.isNull())
        viewModel_->saveDocument(fileName);
}

void MainWindow::displayError(const QString &error)
{
    QMessageBox::critical(this, tr("Error"), error, QMessageBox::StandardButton::Ok);
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    switch (promptToSaveDirtyDocument()) {
    case Save:
        save();
    case DontSave:
        event->accept();
        break;
    case Cancel:
        event->ignore();
    }
}

MainWindow::SavePromptButton MainWindow::promptToSaveDirtyDocument()
{
    if (viewModel_->faceModel() == nullptr || !viewModel_->faceModel()->isModifiedSinceSave()) {
        return DontSave; // ignore this dialog and move on
    }

    QStringList buttons { tr("Save"), tr("Don't Save"), tr("Cancel") };
    auto ret = QMessageBox::information(this,
                                        "",
                                        tr("Do you want to save the changes you made? Your changes will be lost if you don't save them."),
                                        buttons[0], buttons[1], buttons[2], 0, 2);
    return static_cast<MainWindow::SavePromptButton>(ret);
}

void MainWindow::displayFace(f2b::font::face& face)
{
    if (faceWidget_ == nullptr) {
        faceWidget_ = new FaceWidget();
        faceWidget_->setShowsNonExportedItems(viewModel_->shouldShowNonExportedGlyphs());
        ui_->faceGraphicsView->scene()->addItem(faceWidget_);

        connect(faceWidget_, &FaceWidget::currentGlyphIndexChanged,
                this, &MainWindow::switchActiveGlyph);
        connect(faceWidget_, &FaceWidget::glyphExportedStateChanged,
                this, &MainWindow::setGlyphExported);
        connect(ui_->actionShow_non_exported_Glyphs, &QAction::toggled,
                [&](bool checked) {
            viewModel_->setShouldShowNonExportedGlyphs(checked);
            faceWidget_->setShowsNonExportedItems(checked);
            QApplication::processEvents();
            ui_->faceGraphicsView->setSceneRect(faceWidget_->rect());
        });
    }

    auto margins = viewModel_->faceModel()->originalFaceMargins();
    faceWidget_->load(face, margins);

    ui_->showNonExportedGlyphsCheckBox->setVisible(true);
    ui_->faceInfoSeparator->setVisible(true);

    auto faceInfo = viewModel_->faceModel()->faceInfo();
    updateFaceInfoLabel(faceInfo);
    updateDefaultFontName(faceInfo);
    ui_->faceInfoLabel->setVisible(true);

    auto glyph = viewModel_->faceModel()->activeGlyph();
    if (glyph.has_value()) {
        displayGlyph(glyph.value());
        faceWidget_->setCurrentGlyphIndex(viewModel_->faceModel()->activeGlyphIndex());
        viewModel_->setActiveGlyphIndex(viewModel_->faceModel()->activeGlyphIndex());
    } else if (auto g = glyphWidget_.get()) {
        ui_->glyphGraphicsView->scene()->removeItem(g);
        glyphWidget_.release();
    }
    updateResetActions();
}

void MainWindow::setGlyphExported(std::size_t index, bool isExported)
{
    pushUndoCommand(new Command(tr("Toggle Glyph Exported"), [&, index, isExported] {
        viewModel_->setGlyphExported(index, !isExported);
        auto faceModel = viewModel_->faceModel();
        updateFaceInfoLabel(faceModel->faceInfo());
        if (!faceWidget_->showsNonExportedItems()) {
            auto margins = faceModel->originalFaceMargins();
            faceWidget_->load(faceModel->face(), margins);
            faceWidget_->setCurrentGlyphIndex(index);
            glyphWidget_->load(faceModel->face().glyph_at(index), margins);
        } else {
            faceWidget_->updateGlyphInfo(index, {}, !isExported);
        }

    }, [&, index, isExported] {
        auto faceModel = viewModel_->faceModel();
        auto shouldUpdateCurrentIndex = !isExported && !faceWidget_->showsNonExportedItems();

        std::optional<std::size_t> nextIndex {};
        if (shouldUpdateCurrentIndex) {
            // Find index of the next exported item
            auto i = std::next(faceModel->face().exported_glyph_ids().find(index));
            if (i != faceModel->face().exported_glyph_ids().end()) {
                nextIndex = *i;
            }
        }

        viewModel_->setGlyphExported(index, isExported);
        updateFaceInfoLabel(faceModel->faceInfo());

        if (shouldUpdateCurrentIndex) {
            auto margins = faceModel->originalFaceMargins();
            faceWidget_->load(faceModel->face(), margins);
            faceWidget_->setCurrentGlyphIndex(nextIndex);
            if (nextIndex.has_value()) {
                glyphWidget_->load(faceModel->face().glyph_at(nextIndex.value()), margins);
            }
        } else {
            faceWidget_->updateGlyphInfo(index, {}, isExported);
        }
    }));
}

void MainWindow::updateFaceInfoLabel(const FaceInfo &faceInfo)
{
    QStringList lines;
    lines << faceInfo.fontName;
    lines << tr("Size (full): %1x%2px").arg(faceInfo.size.width).arg(faceInfo.size.height);
    lines << tr("Size (adjusted): %1x%2px").arg(faceInfo.sizeWithoutMargins.width).arg(faceInfo.sizeWithoutMargins.height);
    lines << QString("%1, %2").arg(tr("%n Glyph(s)", "", faceInfo.numberOfGlyphs),
                                   tr("%n to export", "", faceInfo.numberOfExportedGlyphs));
    ui_->faceInfoLabel->setText(lines.join("\n"));
}

void MainWindow::updateDefaultFontName(const FaceInfo &faceInfo)
{
    auto fontName = faceInfo.fontName.toLower();
    fontName.remove(',');
    fontName.replace(' ', '_');
    ui_->fontArrayNameEdit->setText(fontName);
}

void MainWindow::displayGlyph(const f2b::font::glyph& glyph)
{
    auto margins = viewModel_->faceModel()->originalFaceMargins();
    if (!glyphWidget_.get()) {
        glyphWidget_ = std::make_unique<GlyphWidget>(glyph, margins);
        ui_->glyphGraphicsView->scene()->addItem(glyphWidget_.get());

        connect(glyphWidget_.get(), &GlyphWidget::pixelsChanged,
                this, &MainWindow::editGlyph);
    } else {
        glyphWidget_->load(glyph, margins);
    }
    updateResetActions();
    ui_->glyphGraphicsView->fitInView(glyphWidget_->boundingRect(), Qt::KeepAspectRatio);
}

void MainWindow::editGlyph(const BatchPixelChange& change)
{
    auto currentIndex = viewModel_->faceModel()->activeGlyphIndex();
    if (currentIndex.has_value()) {

        auto applyChange = [&, currentIndex, change](BatchPixelChange::ChangeType type) -> std::function<void()> {
            return [&, currentIndex, change, type] {
                viewModel_->modifyGlyph(currentIndex.value(), change, type);
                updateResetActions();
                glyphWidget_->applyChange(change, type);
                faceWidget_->updateGlyphInfo(currentIndex.value(), viewModel_->faceModel()->activeGlyph().value());
                viewModel_->updateDocumentTitle();
            };
        };

        pushUndoCommand(new Command(tr("Edit Glyph"),
                                    applyChange(BatchPixelChange::ChangeType::Reverse),
                                    applyChange(BatchPixelChange::ChangeType::Normal)));
    }
}

void MainWindow::switchActiveGlyph(std::optional<std::size_t> newIndex)
{
    auto currentIndex = viewModel_->faceModel()->activeGlyphIndex();
    if (currentIndex == newIndex) {
        return;
    }

    if (currentIndex.has_value() && newIndex.has_value()) {

        if (!pendingSwitchGlyphCommand_) {
            pendingSwitchGlyphCommand_ = std::make_unique<SwitchActiveGlyphCommand>(faceWidget_, viewModel_.get(),
                                                                                    currentIndex.value(), newIndex.value());
        } else {
            pendingSwitchGlyphCommand_->setToIndex(newIndex.value());
        }
        pendingSwitchGlyphCommand_->redo();
    } else {
        faceWidget_->setCurrentGlyphIndex(newIndex);
        viewModel_->setActiveGlyphIndex(newIndex);
    }
}

void MainWindow::resetCurrentGlyph()
{
    f2b::font::glyph currentGlyphState { viewModel_->faceModel()->activeGlyph().value() };
    auto glyphIndex = viewModel_->faceModel()->activeGlyphIndex().value();

    pushUndoCommand(new Command(tr("Reset Glyph"), [&, currentGlyphState, glyphIndex] {
        viewModel_->modifyGlyph(glyphIndex, currentGlyphState);
        viewModel_->updateDocumentTitle();
        displayGlyph(viewModel_->faceModel()->activeGlyph().value());
        faceWidget_->updateGlyphInfo(glyphIndex, viewModel_->faceModel()->activeGlyph().value());
    }, [&, glyphIndex] {
        viewModel_->resetGlyph(glyphIndex);
        viewModel_->updateDocumentTitle();
        displayGlyph(viewModel_->faceModel()->activeGlyph().value());
        faceWidget_->updateGlyphInfo(glyphIndex, viewModel_->faceModel()->activeGlyph().value());
    }));
}

void MainWindow::resetFont()
{
    auto message = tr("Are you sure you want to reset all changes to the font? This operation cannot be undone.");
    auto result = QMessageBox::warning(this, tr("Reset Font"), message, QMessageBox::Reset, QMessageBox::Cancel);
    if (result == QMessageBox::Reset) {
        viewModel_->faceModel()->reset();
        viewModel_->updateDocumentTitle();
        undoStack_->clear();
        updateResetActions();
        displayFace(viewModel_->faceModel()->face());
    }
}

void MainWindow::updateResetActions()
{
    if (viewModel_->faceModel() == nullptr) {
        ui_->actionReset_Glyph->setEnabled(false);
        ui_->actionReset_Font->setEnabled(false);
    } else {
        auto currentIndex = viewModel_->faceModel()->activeGlyphIndex();
        if (currentIndex.has_value()) {
            ui_->actionReset_Glyph->setEnabled(viewModel_->faceModel()->isGlyphModified(currentIndex.value()));
        } else {
            ui_->actionReset_Glyph->setEnabled(false);
        }
        ui_->actionReset_Font->setEnabled(viewModel_->faceModel()->isModified());
    }
}

void MainWindow::debounceFontNameChanged(const QString &fontName)
{
    if (fontNameDebounceTimer_ == nullptr) {
        fontNameDebounceTimer_ = std::make_unique<QTimer>();
        fontNameDebounceTimer_->setInterval(300);
        fontNameDebounceTimer_->setSingleShot(true);
    } else {
        fontNameDebounceTimer_->stop();
        fontNameDebounceTimer_->disconnect();
    }

    connect(fontNameDebounceTimer_.get(), &QTimer::timeout, [&, fontName] {
        viewModel_->setFontArrayName(fontName);
    });

    fontNameDebounceTimer_->start();
}

void MainWindow::displaySourceCode()
{
    ui_->stackedWidget->setCurrentWidget(ui_->sourceCodeContainer);
    QElapsedTimer timer;
    timer.start();
    ui_->sourceCodeTextBrowser->setPlainText(viewModel_->sourceCode());
    qDebug() << "Displaying finished in" << timer.elapsed() << "ms";
}

void MainWindow::exportSourceCode()
{
    ui_->statusBar->clearMessage();

    QString directoryPath = viewModel_->lastSourceCodeDirectory();
    if (directoryPath.isNull()) {
        directoryPath = defaultDialogDirectory();
    }

    auto dialog = std::make_shared<QFileDialog>(this, tr("Save Source Code"), directoryPath);
    dialog->setAcceptMode(QFileDialog::AcceptSave);
    dialog->setFileMode(QFileDialog::AnyFile);

    connect(dialog.get(), &QFileDialog::finished, [=](int) {
        dialog->setParent(nullptr);
        auto files = dialog->selectedFiles();
        if (!files.isEmpty()) {
            auto filePath = files.first();
            if (!filePath.isNull()) {
                QFile output(filePath);
                if (output.open(QFile::WriteOnly | QFile::Truncate)) {
                    output.write(ui_->sourceCodeTextBrowser->document()->toPlainText().toUtf8());
                    output.close();
                    viewModel_->setLastSourceCodeDirectory(filePath);
                    ui_->statusBar->showMessage(tr("Source code successfully exported."), 5000);
                } else {
                    displayError(tr("Unable to write to file: ") + filePath);
                }
            }
        }
    });

    dialog->open();
}

void MainWindow::pushUndoCommand(QUndoCommand *command)
{
    bool shouldPushSwitchGlyphCommand = pendingSwitchGlyphCommand_ != nullptr;

    if (shouldPushSwitchGlyphCommand) {
        undoStack_->beginMacro(command->text());
        undoStack_->push(pendingSwitchGlyphCommand_.get());
        pendingSwitchGlyphCommand_.release();
    }

    undoStack_->push(command);

    if (shouldPushSwitchGlyphCommand) {
        undoStack_->endMacro();
    }
}


================================================
FILE: app/mainwindow.h
================================================
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGraphicsScene>
#include <QUndoStack>
#include <QTimer>

#include "mainwindowmodel.h"
#include "updatehelper.h"
#include "facewidget.h"
#include "glyphwidget.h"
#include "batchpixelchange.h"
#include "command.h"

#include <memory>

namespace Ui {
class MainWindow;
}

class QLabel;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    virtual ~MainWindow();

protected:
    virtual void closeEvent(QCloseEvent *event) override;

private slots:
    void displayFace(f2b::font::face& face);

private:
    void connectUpdateHelper();
    void connectUIInputs();
    void connectViewModelOutputs();
    void initUI();
    void setupActions();

    void showUpdateDialog(std::optional<UpdateHelper::Update> update);

    void showAboutDialog();
    void showFontDialog();
    void showOpenDocumentDialog();
    void showCloseDocumentDialogIfNeeded();
    void showAddGlyphDialog();
    void showDeleteGlyphDialog();
    void save();
    void saveAs();
    void resetCurrentGlyph();
    void resetFont();
    void displayGlyph(const f2b::font::glyph& glyph);
    void updateUI(UIState uiState);
    void editGlyph(const BatchPixelChange& change);
    void switchActiveGlyph(std::optional<std::size_t> newIndex);
    void setGlyphExported(std::size_t index, bool isExported);
    void updateResetActions();
    void updateFaceInfoLabel(const FaceInfo& faceInfo);
    void updateDefaultFontName(const FaceInfo& faceInfo);

    void displaySourceCode();
    void exportSourceCode();
    void closeCurrentDocument();
    void displayError(const QString& error);
    void pushUndoCommand(QUndoCommand *command);

    void debounceFontNameChanged(const QString& fontName);

    QString defaultDialogDirectory() const;

    enum SavePromptButton {
        Save,
        DontSave,
        Cancel
    };

    SavePromptButton promptToSaveDirtyDocument();

    Ui::MainWindow *ui_;

    std::unique_ptr<GlyphWidget> glyphWidget_ {};
    FaceWidget *faceWidget_ { nullptr };
    QLabel *statusLabel_;
    std::unique_ptr<UpdateHelper> updateHelper_ { std::make_unique<UpdateHelper>() };
    std::unique_ptr<MainWindowModel> viewModel_ { std::make_unique<MainWindowModel>() };
    std::unique_ptr<QGraphicsScene> faceScene_ { std::make_unique<QGraphicsScene>() };
    std::unique_ptr<QUndoStack> undoStack_ { std::make_unique<QUndoStack>() };
    std::unique_ptr<QTimer> fontNameDebounceTimer_ {};

    std::unique_ptr<SwitchActiveGlyphCommand> pendingSwitchGlyphCommand_ {};
};

#endif // MAINWINDOW_H


================================================
FILE: app/mainwindow.ui
================================================
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>724</width>
    <height>619</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>FontEdit</string>
  </property>
  <property name="windowIcon">
   <iconset resource="assets.qrc">
    <normaloff>:/icon/assets/icon/fontedit256.png</normaloff>:/icon/assets/icon/fontedit256.png</iconset>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout_2">
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <property name="tabShape">
       <enum>QTabWidget::Triangular</enum>
      </property>
      <property name="currentIndex">
       <number>0</number>
      </property>
      <widget class="QWidget" name="tabEdit">
       <attribute name="title">
        <string>Edit Font</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout">
        <item row="0" column="0">
         <layout class="QHBoxLayout" name="horizontalLayout">
          <property name="spacing">
           <number>0</number>
          </property>
          <item>
           <widget class="QToolButton" name="importFontButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="openButton">
            <property name="text">
             <string/>
            </property>
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="saveButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
            <property name="shortcut">
             <string>Ctrl+R</string>
            </property>
           </widget>
          </item>
          <item>
           <spacer name="horizontalSpacer_4">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeType">
             <enum>QSizePolicy::Fixed</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>8</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
          <item>
           <widget class="QToolButton" name="addGlyphButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="deleteGlyphButton">
            <property name="text">
             <string/>
            </property>
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="copyButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="pasteButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="undoButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="redoButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QToolButton" name="resetGlyphButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <spacer name="horizontalSpacer_5">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeType">
             <enum>QSizePolicy::Fixed</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>8</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
          <item>
           <widget class="QToolButton" name="resetFontButton">
            <property name="iconSize">
             <size>
              <width>24</width>
              <height>24</height>
             </size>
            </property>
           </widget>
          </item>
          <item>
           <spacer name="horizontalSpacer">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>40</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
         </layout>
        </item>
        <item row="1" column="0">
         <widget class="GlyphGraphicsView" name="glyphGraphicsView">
          <property name="alignment">
           <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
          </property>
         </widget>
        </item>
        <item row="1" column="1">
         <layout class="QVBoxLayout" name="verticalLayout_8">
          <item>
           <widget class="QGraphicsView" name="faceGraphicsView">
            <property name="minimumSize">
             <size>
              <width>240</width>
              <height>0</height>
             </size>
            </property>
            <property name="maximumSize">
             <size>
              <width>240</width>
              <height>16777215</height>
             </size>
            </property>
            <property name="horizontalScrollBarPolicy">
             <enum>Qt::ScrollBarAlwaysOff</enum>
            </property>
            <property name="alignment">
             <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QCheckBox" name="showNonExportedGlyphsCheckBox">
            <property name="statusTip">
             <string>Toggle exported state by pressing Space on a selected glyph</string>
            </property>
            <property name="text">
             <string>Show non-exported Glyphs</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="Line" name="faceInfoSeparator">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QLabel" name="faceInfoLabel">
            <property name="enabled">
             <bool>true</bool>
            </property>
            <property name="maximumSize">
             <size>
              <width>240</width>
              <height>16777215</height>
             </size>
            </property>
            <property name="text">
             <string>TextLabel</string>
            </property>
            <property name="alignment">
             <set>Qt::AlignCenter</set>
            </property>
            <property name="wordWrap">
             <bool>true</bool>
            </property>
           </widget>
          </item>
         </layout>
        </item>
        <item row="0" column="1">
         <spacer name="horizontalSpacer_3">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
          <property name="sizeType">
           <enum>QSizePolicy::Ignored</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>237</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tabCode">
       <attribute name="title">
        <string>Source Code</string>
       </attribute>
       <layout class="QHBoxLayout" name="horizontalLayout_3">
        <item>
         <widget class="QStackedWidget" name="stackedWidget">
          <property name="currentIndex">
           <number>0</number>
          </property>
          <widget class="QWidget" name="sourceCodeContainer">
           <layout class="QHBoxLayout" name="horizontalLayout_2">
            <property name="leftMargin">
             <number>0</number>
            </property>
            <property name="topMargin">
             <number>0</number>
            </property>
            <property name="rightMargin">
             <number>0</number>
            </property>
            <property name="bottomMargin">
             <number>0</number>
            </property>
            <item>
             <widget class="QTextBrowser" name="sourceCodeTextBrowser">
              <property name="lineWrapMode">
               <enum>QTextEdit::NoWrap</enum>
              </property>
             </widget>
            </item>
           </layout>
          </widget>
          <widget class="QWidget" name="spinnerContainer">
           <layout class="QHBoxLayout" name="horizontalLayout_4">
            <item>
             <widget class="QLabel" name="label">
              <property name="text">
               <string>Updating source code...</string>
              </property>
              <property name="alignment">
               <set>Qt::AlignCenter</set>
              </property>
             </widget>
            </item>
           </layout>
          </widget>
         </widget>
        </item>
        <item>
         <layout class="QVBoxLayout" name="verticalLayout_4">
          <item>
           <widget class="QGroupBox" name="groupBox_2">
            <property name="title">
             <string>Output Format</string>
            </property>
            <layout class="QVBoxLayout" name="verticalLayout_3">
             <item>
              <widget class="QComboBox" name="formatComboBox"/>
             </item>
             <item>
              <widget class="QRadioButton" name="exportSubsetButton">
               <property name="text">
                <string>Export Selected Glyphs</string>
               </property>
               <attribute name="buttonGroup">
                <string notr="true">exportMethodButtonGroup</string>
               </attribute>
              </widget>
             </item>
             <item>
              <widget class="QRadioButton" name="exportAllButton">
               <property name="text">
                <string>Export All Glyphs</string>
               </property>
               <attribute name="buttonGroup">
                <string notr="true">exportMethodButtonGroup</string>
               </attribute>
              </widget>
             </item>
            </layout>
           </widget>
          </item>
          <item>
           <widget class="QGroupBox" name="groupBox">
            <property name="sizePolicy">
             <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
            <property name="title">
             <string>Misc Options</string>
            </property>
            <layout class="QVBoxLayout" name="verticalLayout">
             <item>
              <widget class="QCheckBox" name="invertBitsCheckBox">
               <property name="text">
                <string>Invert Bits</string>
               </property>
              </widget>
             </item>
             <item>
              <widget class="QCheckBox" name="bitNumberingCheckBox">
               <property name="text">
                <string>Reverse Bits (MSB)</string>
               </property>
              </widget>
             </item>
             <item>
              <widget class="QCheckBox" name="lineSpacingCheckBox">
               <property name="text">
                <string>Include Line Spacing</string>
               </property>
              </widget>
             </item>
            </layout>
           </widget>
          </item>
          <item>
           <widget class="QGroupBox" name="groupBox_3">
            <property name="title">
             <string>Font Array Name</string>
            </property>
            <layout class="QHBoxLayout" name="horizontalLayout_5">
             <item>
              <widget class="QLineEdit" name="fontArrayNameEdit">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Ignored" vsizetype="Fixed">
                 <horstretch>0</horstretch>
                 <verstretch>0</verstretch>
                </sizepolicy>
               </property>
               <property name="placeholderText">
                <string>font</string>
               </property>
              </widget>
             </item>
            </layout>
           </widget>
          </item>
          <item>
           <widget class="QGroupBox" name="groupBox_4">
            <property name="title">
             <string>Indentation</string>
            </property>
            <layout class="QVBoxLayout" name="verticalLayout_5">
             <item>
              <widget class="QComboBox" name="indentationComboBox"/>
             </item>
            </layout>
           </widget>
          </item>
          <item>
           <spacer name="verticalSpacer">
            <property name="orientation">
             <enum>Qt::Vertical</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>20</width>
              <height>40</height>
             </size>
            </property>
           </spacer>
          </item>
          <item>
           <widget class="QPushButton" name="printButton">
            <property name="text">
             <string>Print</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QPushButton" name="exportButton">
            <property name="text">
             <string>Export Source Code...</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
       </layout>
      </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>724</width>
     <height>22</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFile">
    <property name="title">
     <string>File</string>
    </property>
    <addaction name="actionImport_Font"/>
    <addaction name="actionOpen"/>
    <addaction name="separator"/>
    <addaction name="actionSave"/>
    <addaction name="actionSave_As"/>
    <addaction name="actionExport"/>
    <addaction name="actionClose"/>
    <addaction name="separator"/>
    <addaction name="actionPrint"/>
    <addaction name="separator"/>
    <addaction name="actionQuit"/>
   </widget>
   <widget class="QMenu" name="menuEdit">
    <property name="title">
     <string>Edit</string>
    </property>
    <addaction name="actionAdd_Glyph"/>
    <addaction name="actionDelete_Glyph"/>
    <addaction name="separator"/>
    <addaction name="actionCopy_Glyph"/>
    <addaction name="actionPaste_Glyph"/>
    <addaction name="separator"/>
    <addaction name="actionReset_Glyph"/>
    <addaction name="actionReset_Font"/>
   </widget>
   <widget class="QMenu" name="menuHelp">
    <property name="title">
     <string>Help</string>
    </property>
    <addaction name="actionAbout"/>
    <addaction name="actionCheck_for_Updates"/>
   </widget>
   <widget class="QMenu" name="menuView">
    <property name="title">
     <string>View</string>
    </property>
    <addaction name="actionShow_non_exported_Glyphs"/>
   </widget>
   <addaction name="menuFile"/>
   <addaction name="menuEdit"/>
   <addaction name="menuView"/>
   <addaction name="menuHelp"/>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
  <action name="actionNew">
   <property name="text">
    <string>New</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+N</string>
   </property>
  </action>
  <action name="actionImport_Font">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/font.svg</normaloff>:/toolbar/assets/font.svg</iconset>
   </property>
   <property name="text">
    <string>Import Font</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+N</string>
   </property>
  </action>
  <action name="actionReset_Glyph">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/reset.svg</normaloff>:/toolbar/assets/reset.svg</iconset>
   </property>
   <property name="text">
    <string>Reset Glyph</string>
   </property>
  </action>
  <action name="actionExport">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/code.svg</normaloff>:/toolbar/assets/code.svg</iconset>
   </property>
   <property name="text">
    <string>Export...</string>
   </property>
  </action>
  <action name="actionSave">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/save.svg</normaloff>:/toolbar/assets/save.svg</iconset>
   </property>
   <property name="text">
    <string>Save</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+S</string>
   </property>
  </action>
  <action name="actionReset_Font">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/clear.svg</normaloff>:/toolbar/assets/clear.svg</iconset>
   </property>
   <property name="text">
    <string>Reset Font</string>
   </property>
  </action>
  <action name="actionPrint">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/print.svg</normaloff>:/toolbar/assets/print.svg</iconset>
   </property>
   <property name="text">
    <string>Print...</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+P</string>
   </property>
  </action>
  <action name="actionSave_As">
   <property name="text">
    <string>Save As...</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+Shift+S</string>
   </property>
  </action>
  <action name="actionAdd_Glyph">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/add-glyph.svg</normaloff>:/toolbar/assets/add-glyph.svg</iconset>
   </property>
   <property name="text">
    <string>Add Glyph</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+Shift+N</string>
   </property>
  </action>
  <action name="actionQuit">
   <property name="text">
    <string>Quit</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+Q</string>
   </property>
  </action>
  <action name="actionCopy_Glyph">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/copy.svg</normaloff>:/toolbar/assets/copy.svg</iconset>
   </property>
   <property name="text">
    <string>Copy Glyph</string>
   </property>
  </action>
  <action name="actionPaste_Glyph">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/paste.svg</normaloff>:/toolbar/assets/paste.svg</iconset>
   </property>
   <property name="text">
    <string>Paste Glyph</string>
   </property>
  </action>
  <action name="actionOpen">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/open.svg</normaloff>:/toolbar/assets/open.svg</iconset>
   </property>
   <property name="text">
    <string>Open...</string>
   </property>
   <property name="shortcut">
    <string>Ctrl+O</string>
   </property>
  </action>
  <action name="actionOpen_Recent">
   <property name="text">
    <string>Recent files</string>
   </property>
  </action>
  <action name="actionClose">
   <property name="text">
    <string>Close</string>
   </property>
  </action>
  <action name="actionAbout">
   <property name="text">
    <string>About FontEdit</string>
   </property>
  </action>
  <action name="actionDelete_Glyph">
   <property name="icon">
    <iconset resource="assets.qrc">
     <normaloff>:/toolbar/assets/delete-glyph.svg</normaloff>:/toolbar/assets/delete-glyph.svg</iconset>
   </property>
   <property name="text">
    <string>Delete Glyph</string>
   </property>
  </action>
  <action name="actionShow_non_exported_Glyphs">
   <property name="checkable">
    <bool>true</bool>
   </property>
   <property name="checked">
    <bool>true</bool>
   </property>
   <property name="text">
    <string>Show non-exported Glyphs</string>
   </property>
  </action>
  <action name="actionCheck_for_Updates">
   <property name="text">
    <string>Check for Updates...</string>
   </property>
  </action>
 </widget>
 <customwidgets>
  <customwidget>
   <class>GlyphGraphicsView</class>
   <extends>QGraphicsView</extends>
   <header>glyphgraphicsview.h</header>
  </customwidget>
 </customwidgets>
 <resources>
  <include location="assets.qrc"/>
 </resources>
 <connections>
  <connection>
   <sender>showNonExportedGlyphsCheckBox</sender>
   <signal>toggled(bool)</signal>
   <receiver>actionShow_non_exported_Glyphs</receiver>
   <slot>setChecked(bool)</slot>
   <hints>
    <hint type="sourcelabel">
     <x>563</x>
     <y>508</y>
    </hint>
    <hint type="destinationlabel">
     <x>-1</x>
     <y>-1</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>actionShow_non_exported_Glyphs</sender>
   <signal>toggled(bool)</signal>
   <receiver>showNonExportedGlyphsCheckBox</receiver>
   <slot>setChecked(bool)</slot>
   <hints>
    <hint type="sourcelabel">
     <x>-1</x>
     <y>-1</y>
    </hint>
    <hint type="destinationlabel">
     <x>563</x>
     <y>508</y>
    </hint>
   </hints>
  </connection>
 </connections>
 <buttongroups>
  <buttongroup name="exportMethodButtonGroup"/>
 </buttongroups>
</ui>


================================================
FILE: app/mainwindowmodel.cpp
================================================
#include "mainwindowmodel.h"
#include "sourcecoderunnable.h"
#include "f2b_qt_compat.h"
#include <f2b.h>

#include <QDebug>
#include <QThreadPool>
#include <QFile>
#include <QDataStream>
#include <QDir>

#include <iostream>
#include <thread>

Q_DECLARE_METATYPE(f2b::source_code_options::bit_numbering_type);
Q_DECLARE_METATYPE(f2b::source_code_options::export_method_type);

namespace SettingsKey {
static const QString showNonExportedGlyphs = "main_window/show_non_expoerted_glyphs";
static const QString exportMethod = "source_code_options/export_method";
static const QString bitNumbering = "source_code_options/bit_numbering";
static const QString invertBits = "source_code_options/invert_bits";
static const QString includeLineSpacing = "source_code_options/include_line_spacing";
static const QString format = "source_code_options/format";
static const QString indentation = "source_code_options/indentation";
static const QString documentPath = "source_code_options/document_path";
static const QString lastDocumentDirectory = "source_code_options/last_document_directory";
static const QString lastSourceCodeDirectory = "source_code_options/last_source_code_directory";
}

bool operator==(const UIState& lhs, const UIState& rhs)
{
    return lhs.actions == rhs.actions &&
            lhs.statusBarMessage == rhs.statusBarMessage &&
            lhs.lastUserAction == rhs.lastUserAction &&
            lhs.selectedTab == rhs.selectedTab;
}

bool operator!=(const UIState& lhs, const UIState& rhs)
{
    return !(lhs == rhs);
}

MainWindowModel::MainWindowModel(QObject *parent) :
    QObject(parent)
{
    shouldShowNonExportedGlyphs_ = settings_.value(SettingsKey::showNonExportedGlyphs, true).toBool();

    sourceCodeOptions_.export_method =
            qvariant_cast<f2b::source_code_options::export_method_type>(
                settings_.value(SettingsKey::exportMethod, f2b::source_code_options::export_selected)
                );
    sourceCodeOptions_.bit_numbering =
            qvariant_cast<f2b::source_code_options::bit_numbering_type>(
                settings_.value(SettingsKey::bitNumbering, f2b::source_code_options::lsb)
                );
    sourceCodeOptions_.invert_bits = settings_.value(SettingsKey::invertBits, false).toBool();
    sourceCodeOptions_.include_line_spacing = settings_.value(SettingsKey::includeLineSpacing, false).toBool();
    sourceCodeOptions_.indentation = from_qvariant(settings_.value(SettingsKey::indentation, to_qvariant(f2b::source_code::tab {})));

    formats_.insert(QString::fromStdString(std::string(f2b::format::c::identifier)), "C/C++");
    formats_.insert(QString::fromStdString(std::string(f2b::format::arduino::identifier)), "Arduino");
    formats_.insert(QString::fromStdString(std::string(f2b::format::python_list::identifier)), "Python List");
    formats_.insert(QString::fromStdString(std::string(f2b::format::python_bytes::identifier)), "Python Bytes");

    currentFormat_ = settings_.value(SettingsKey::format, formats_.firstKey()).toString();

    indentationStyles_.push_back({ f2b::source_code::tab {}, tr("Tab") });
    for (std::size_t i = 1; i <= 8; ++i) {
        indentationStyles_.push_back({ f2b::source_code::space {i}, tr("%n Space(s)", "", i) });
    }

    connect(this, &MainWindowModel::runnableFinished,
            this, &MainWindowModel::sourceCodeChanged,
            Qt::BlockingQueuedConnection);

    qDebug() << "output format:" << currentFormat_;
}

void MainWindowModel::restoreSession()
{
    auto path = settings_.value(SettingsKey::documentPath).toString();
    if (!path.isNull()) {
        openDocument(path, true);
    } else {
        updateDocumentTitle();
    }
}

void MainWindowModel::registerInputEvent(InputEvent e)
{
    auto state { uiState_ };
    if (std::holds_alternative<UIState::InterfaceAction>(e)) {
        auto action = std::get<UIState::InterfaceAction>(e);
        switch (action) {
        case UIState::ActionTabEdit:
            state.selectedTab = UIState::TabEdit;
            break;
        case UIState::ActionTabCode:
            state.selectedTab = UIState::TabCode;
            break;
        default:
            break;
        }
    } else if (std::holds_alternative<UIState::UserAction>(e)) {
        auto action = std::get<UIState::UserAction>(e);
        state.lastUserAction = action;
        switch (action) {
        case UIState::UserIdle:
            state.statusBarMessage = UIState::MessageIdle;
            state.actions.reset();
            break;
        case UIState::UserLoadedDocument:
            state.statusBarMessage = UIState::MessageLoadedFace;
            state.actions.reset();
            state.actions.set(UIState::ActionAddGlyph);
            state.actions.set(UIState::ActionSave);
            state.actions.set(UIState::ActionClose);
            state.actions.set(UIState::ActionPrint);
            state.actions.set(UIState::ActionExport);
            state.actions.set(UIState::ActionTabCode);
            break;
        case UIState::UserLoadedGlyph:
            state.statusBarMessage = UIState::MessageLoadedGlyph;
            state.actions.set(UIState::ActionDeleteGlyph);
            state.actions.set(UIState::ActionCopy);
            break;
        }
        state.actions.set(UIState::ActionTabEdit);
    }

    if (state != uiState_) {
        uiState_ = state;
        emit uiStateChanged(uiState_);
    }
}

void MainWindowModel::updateDocumentTitle()
{
    QString name;
    if (documentPath_.has_value()) {
        QFileInfo fileInfo {documentPath_.value()};
        name = fileInfo.fileName();
    } else {
        name = tr("New Document");
    }

    if (auto faceModel = fontFaceViewModel_.get()) {
        if (faceModel->isModifiedSinceSave()) {
            name += " - ";
            name += tr("Edited");
        }
    }
    if (name != documentTitle_) {
        documentTitle_ = name;
        emit documentTitleChanged(documentTitle_);
    }
}

void MainWindowModel::importFont(const QFont &font)
{
    fontFaceViewModel_ = std::make_unique<FontFaceViewModel>(font);
    registerInputEvent(UIState::UserLoadedDocument);
    setDocumentPath({});
    emit faceLoaded(fontFaceViewModel_->face());
    updateDocumentTitle();
}

void MainWindowModel::openDocument(const QString &fileName)
{
    openDocument(fileName, false);
}

void MainWindowModel::openDocument(const QString &fileName, bool failSilently)
{
    try {
        fontFaceViewModel_ = std::make_unique<FontFaceViewModel>(fileName);

        qDebug() << "face loaded from" << fileName;

        registerInputEvent(UIState::UserLoadedDocument);
        setDocumentPath(fileName);
        updateDocumentTitle();
        emit faceLoaded(fontFaceViewModel_->face());

    } catch (std::runtime_error& e) {
        setDocumentPath({});
        updateDocumentTitle();

        qCritical() << e.what();

        if (!failSilently) {
            emit documentError(QString::fromStdString(e.what()));
        }
    }
}

void MainWindowModel::saveDocument(const QString& fileName)
{
    try {
        fontFaceViewModel_->saveToFile(fileName);

        qDebug() << "face saved to" << fileName;

        setDocumentPath(fileName);
        updateDocumentTitle();
    } catch (std::runtime_error& e) {
        qCritical() << e.what();
        emit documentError(QString::fromStdString(e.what()));
    }
}

void MainWindowModel::closeCurrentDocument()
{
    fontFaceViewModel_.release();
    setDocumentPath({});
    updateDocumentTitle();
    registerInputEvent(UIState::UserIdle);
    emit documentClosed();
}

void MainWindowModel::setActiveGlyphIndex(std::optional<std::size_t> index)
{
    if (fontFaceViewModel_->activeGlyphIndex().has_value() and
            fontFaceViewModel_->activeGlyphIndex().value() == index)
    {
        return;
    }

    try {
        fontFaceViewModel_->setActiveGlyphIndex(index);
        registerInputEvent(UIState::UserLoadedGlyph);

        emit activeGlyphChanged(fontFaceViewModel_->activeGlyph());
    } catch (const std::exception& e) {
        qCritical() << e.what();
    }
}

void MainWindowModel::setShouldShowNonExportedGlyphs(bool enabled)
{
    shouldShowNonExportedGlyphs_ = enabled;
    settings_.setValue(SettingsKey::showNonExportedGlyphs, enabled);
}

void MainWindowModel::setExportAllEnabled(bool enabled)
{
    auto exportMethod = enabled ? f2b::source_code_options::export_all : f2b::source_code_options::export_selected;
    sourceCodeOptions_.export_method = exportMethod;
    settings_.setValue(SettingsKey::exportMethod, exportMethod);
    reloadSourceCode();
}

void MainWindowModel::setInvertBits(bool enabled)
{
    sourceCodeOptions_.invert_bits = enabled;
    settings_.setValue(SettingsKey::invertBits, enabled);
    reloadSourceCode();
}

void MainWindowModel::setMSBEnabled(bool enabled)
{
    auto bitNumbering = enabled ? f2b::source_code_options::msb : f2b::source_code_options::lsb;
    sourceCodeOptions_.bit_numbering = bitNumbering;
    settings_.setValue(SettingsKey::bitNumbering, bitNumbering);
    reloadSourceCode();
}

void MainWindowModel::setIncludeLineSpacing(bool enabled)
{
    sourceCodeOptions_.include_line_spacing = enabled;
    settings_.setValue(SettingsKey::includeLineSpacing, enabled);
    reloadSourceCode();
}

void MainWindowModel::setOutputFormat(const QString& format)
{
    currentFormat_ = formats_.key(format, formats_.first());
    settings_.setValue(SettingsKey::format, currentFormat_);
    reloadSourceCode();
}

void MainWindowModel::setIndentation(const QString &indentationLabel)
{
    auto i = std::find_if(indentationStyles_.cbegin(), indentationStyles_.cend(), [&](const auto& pair) -> bool {
        return pair.second == indentationLabel;
    });
    if (i != indentationStyles_.end()) {
        sourceCodeOptions_.indentation = i->first;
        settings_.setValue(SettingsKey::indentation, to_qvariant(i->first));
        reloadSourceCode();
    }
}

QString MainWindowModel::indentationStyleCaption() const
{
    auto i = std::find_if(indentationStyles_.cbegin(), indentationStyles_.cend(), [&](const auto& pair) -> bool {
        return pair.first == sourceCodeOptions_.indentation;
    });
    if (i != indentationStyles_.end()) {
        return i->second;
    }
    return indentationStyles_.front().second;
}

void MainWindowModel::setDocumentPath(const std::optional<QString>& path)
{
    documentPath_ = path;
    if (path.has_value()) {
        settings_.setValue(SettingsKey::documentPath, path.value());
        setLastVisitedDirectory(path.value());
    } else {
        settings_.remove(SettingsKey::documentPath);
    }
}

QString MainWindowModel::lastVisitedDirectory() const
{
    return settings_.value(SettingsKey::lastDocumentDirectory).toString();
}

void MainWindowModel::setLastVisitedDirectory(const QString& path)
{
    settings_.setValue(SettingsKey::lastDocumentDirectory, QFileInfo(path).path());
}

QString MainWindowModel::lastSourceCodeDirectory() const
{
    return settings_.value(SettingsKey::lastSourceCodeDirectory).toString();
}

void MainWindowModel::setLastSourceCodeDirectory(const QString& path)
{
    settings_.setValue(SettingsKey::lastSourceCodeDirectory, QFileInfo(path).path());
}

void MainWindowModel::reloadSourceCode()
{
    /// WIP :)
    emit sourceCodeUpdating();

    auto r = new SourceCodeRunnable { faceModel()->face(), sourceCodeOptions_, currentFormat_, fontArrayName_ };
    r->setCompletionHandler([&](const QString& output) {
        qDebug() << "Source code size:" << output.size() << "bytes";
        std::scoped_lock { sourceCodeMutex_ };
        sourceCode_ = std::move(output);
        emit runnableFinished();
    });
    r->setAutoDelete(true);

    QThreadPool::globalInstance()->start(r);
}

void MainWindowModel::resetGlyph(std::size_t index)
{
    fontFaceViewModel_->resetGlyph(index);
    reloadSourceCode();
}

void MainWindowModel::modifyGlyph(std::size_t index, const f2b::font::glyph &new_glyph)
{
    fontFaceViewModel_->modifyGlyph(index, new_glyph);
    reloadSourceCode();
}

void MainWindowModel::modifyGlyph(std::size_t index,
                                  const BatchPixelChange &change,
                                  BatchPixelChange::ChangeType changeType)
{
    fontFaceViewModel_->modifyGlyph(index, change, changeType);
    reloadSourceCode();
}

void MainWindowModel::appendGlyph(f2b::font::glyph glyph)
{
    fontFaceViewModel_->appendGlyph(std::move(glyph));
    reloadSourceCode();
}

void MainWindowModel::deleteGlyph(std::size_t index)
{
    fontFaceViewModel_->deleteGlyph(index);

    if (index == fontFaceViewModel_->face().num_glyphs() - 1) {
        fontFaceViewModel_->setActiveGlyphIndex(index - 1);
        emit activeGlyphChanged(fontFaceViewModel_->activeGlyph());
    }

    reloadSourceCode();
}

void MainWindowModel::setGlyphExported(std::size_t index, bool isExported)
{
    fontFaceViewModel_->setGlyphExportedState(index, isExported);
    reloadSourceCode();
}


================================================
FILE: app/mainwindowmodel.h
================================================
#ifndef MAINWINDOWMODEL_H
#define MAINWINDOWMODEL_H

#include "fontfaceviewmodel.h"
#include <f2b.h>
#include <memory>
#include <functional>
#include <optional>
#include <bitset>
#include <variant>
#include <vector>
#include <mutex>

#include <QMap>
#include <QSettings>

struct UIState {
    enum InterfaceAction {
        ActionAddGlyph = 0,
        ActionDeleteGlyph,
        ActionSave,
        ActionClose,
        ActionCopy,
        ActionPaste,
        ActionPrint,
        ActionExport,
        ActionTabEdit,
        ActionTabCode,
        ActionCount,
        ActionFirst = ActionAddGlyph
    };

    enum UserAction {
        UserIdle = 0,
        UserLoadedDocument,
        UserLoadedGlyph,
    };

    enum Message {
        MessageIdle = 0,
        MessageLoadedFace,
        MessageLoadedGlyph
    };

    enum Tab {
        TabEdit,
        TabCode
    };

    std::bitset<ActionCount> actions;
    UserAction lastUserAction;
    Message statusBarMessage;
    Tab selectedTab;
};


class MainWindowModel: public QObject
{
    Q_OBJECT

public:

    using InputEvent = std::variant<UIState::InterfaceAction,UIState::UserAction>;

    explicit MainWindowModel(QObject *parent = nullptr);
    void restoreSession();

    FontFaceViewModel* faceModel() const {
        return fontFaceViewModel_.get();
    }

    const UIState& uiState() const { return uiState_; }

    Qt::CheckState shouldShowNonExportedGlyphs() const {
        return shouldShowNonExportedGlyphs_ ? Qt::Checked : Qt::Unchecked;
    }

    bool exportAllEnabled() const {
        return sourceCodeOptions_.export_method == f2b::source_code_options::export_method_type::export_all
                ? Qt::Checked : Qt::Unchecked;
    }

    Qt::CheckState invertBits() const {
        return sourceCodeOptions_.invert_bits ? Qt::Checked : Qt::Unchecked;
    }

    Qt::CheckState msbEnabled() const {
        return sourceCodeOptions_.bit_numbering == f2b::source_code_options::bit_numbering_type::msb
                ? Qt::Checked : Qt::Unchecked;
    }

    Qt::CheckState includeLineSpacing() const {
        return sourceCodeOptions_.include_line_spacing ? Qt::Checked : Qt::Unchecked;
    }

    const QMap<QString,QString>& outputFormats() const {
        return formats_;
    }

    QString outputFormat() const {
        return formats_.value(currentFormat_, formats_.first());
    }

    const std::vector<std::pair<f2b::source_code::indentation, QString>>& indentationStyles() const {
        return indentationStyles_;
    }

    QString indentationStyleCaption() const;

    void registerInputEvent(InputEvent e);

    const std::optional<QString>& currentDocumentPath() const {
        return documentPath_;
    }

    QString documentTitle() const { return documentTitle_; }
    void updateDocumentTitle();

    void setFontArrayName(const QString& fontArrayName) {
        if (fontArrayName_ != fontArrayName) {
            fontArrayName_ = fontArrayName;
            reloadSourceCode();
        }
    }

    QString lastVisitedDirectory() const;

    QString lastSourceCodeDirectory() const;
    void setLastSourceCodeDirectory(const QString& path);

    void resetGlyph(std::size_t index);
    void modifyGlyph(std::size_t index, const f2b::font::glyph &new_glyph);
    void modifyGlyph(std::size_t index,
                     const BatchPixelChange &change,
                     BatchPixelChange::ChangeType changeType);
    void appendGlyph(f2b::font::glyph glyph);
    void deleteGlyph(std::size_t index);
    void setGlyphExported(std::size_t index, bool isExported);

    const QString& sourceCode() {
        std::scoped_lock { sourceCodeMutex_ };
        return sourceCode_;
    }

public slots:
    void importFont(const QFont& font);

    void openDocument(const QString& fileName);
    void saveDocument(const QString& fileName);
    void closeCurrentDocument();

    void setActiveGlyphIndex(std::optional<std::size_t> index);
    void setShouldShowNonExportedGlyphs(bool enabled);
    void setExportAllEnabled(bool enabled);
    void setInvertBits(bool enabled);
    void setMSBEnabled(bool enabled);
    void setIncludeLineSpacing(bool enabled);
    void setOutputFormat(const QString &format); // human-readable
    void setIndentation(const QString &indentationLabel); // human-readable

signals:
    void uiStateChanged(UIState state) const;
    void faceLoaded(f2b::font::face& face) const;
    void activeGlyphChanged(std::optional<f2b::font::glyph> glyph) const;
    void sourceCodeUpdating() const;
    void sourceCodeChanged() const;
    void runnableFinished() const;
    void documentTitleChanged(const QString& title);
    void documentClosed();
    void documentError(const QString& error);

private:
    void reloadSourceCode();
    void setDocumentPath(const std::optional<QString>& path);
    void setLastVisitedDirectory(const QString& path);
    void openDocument(const QString& fileName, bool failSilently);

    UIState uiState_ {};
    std::unique_ptr<FontFaceViewModel> fontFaceViewModel_;
    std::optional<QString> documentPath_;
    QString documentTitle_;
    QString fontArrayName_;
    f2b::source_code_options sourceCodeOptions_;
    bool shouldShowNonExportedGlyphs_;

    QString sourceCode_;
    std::mutex sourceCodeMutex_;

    QMap<QString, QString> formats_; // identifier <-> human-readable
    QString currentFormat_; // identifier
    std::vector<std::pair<f2b::source_code::indentation, QString>> indentationStyles_;
    QSettings settings_;
};

#endif // MAINWINDOWMODEL_H


================================================
FILE: app/qfontfacereader.cpp
================================================
#include "qfontfacereader.h"
#include "f2b_qt_compat.h"

#include <QAbstractTextDocumentLayout>
#include <QFontMetrics>
#include <QImage>
#include <QPainter>
#include <QTextDocument>
#include <QTextFrame>
#include "utf8.h"

using namespace std::literals::string_view_literals;

static constexpr std::string_view ascii_glyphs =
        " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"sv;

QFontFaceReader::QFontFaceReader(const QFont &font, std::string text, std::optional<f2b::font::glyph_size> forced_size) :
    f2b::font::face_reader()
{
    std::string source_text { text.empty() ? ascii_glyphs : std::move(text) };
    num_glyphs_ = source_text.length();

    auto result = read_font(font, std::move(source_text), forced_size);
    sz_ = result.first;
    font_image_ = std::move(result.second);
}

bool QFontFaceReader::is_pixel_set(std::size_t glyph_id, f2b::font::point p) const
{
    p.y += glyph_id * sz_.height;
    return font_image_->pixelColor(f2b::font::qpoint_with_point(p)) == Qt::color1;
}

QString QFontFaceReader::template_text(std::string text)
{
    std::stringstream stream;

    utf8::iterator i(text.begin(), text.begin(), text.end());
    utf8::iterator end(text.end(), text.begin(), text.end());

    while (i != end) {
        auto utf8_begin = i;
        auto utf8_end = ++i;
        stream << std::string(utf8_begin.base(), utf8_end.base()) << "\n";
    }

    return QString::fromStdString(stream.str());
}

std::pair<f2b::font::glyph_size, std::unique_ptr<QImage>> QFontFaceReader::read_font(
            const QFont &font,
            std::string text,
            std::optional<f2b::font::glyph_size> forced_size)
{
    auto text_length = text.length();
    auto template_text = QFontFaceReader::template_text(std::move(text));

    QFontMetrics fm(font);
    qDebug() << font << fm.height() << fm.maxWidth() << fm.leading() << fm.lineSpacing();

    int width = [&] {
        if (forced_size.has_value()) {
            return static_cast<int>(forced_size.value().width);
        }
        return fm.boundingRect(QRect(), Qt::AlignLeft, template_text).width();
    }();
    int height = [&] {
        if (forced_size.has_value()) {
            return static_cast<int>(forced_size.value().height);
        }
        return fm.lineSpacing();
    }();

    QSize img_size(width, height * text_length);

//    qDebug() << "img size" << img_size;

    auto image = std::make_unique<QImage>(img_size, QImage::Format::Format_Mono);
    QPainter p(image.get());
    p.fillRect(QRect(QPoint(), img_size), QColor(Qt::color0));

    QTextDocument doc;
    doc.useDesignMetrics();
    doc.documentLayout()->setPaintDevice(image.get());
    doc.setDefaultFont(font);
    doc.setDocumentMargin(0);
    doc.setPlainText(template_text);
    doc.setTextWidth(img_size.width());

    QTextFrame *rootFrame = doc.rootFrame();
    for (auto it = rootFrame->begin(); !(it.atEnd()); ++it) {
        auto block = it.currentBlock();
        QTextCursor cursor(block);
        auto blockFormat = block.blockFormat();
        blockFormat.setLineHeight(fm.lineSpacing(), QTextBlockFormat::FixedHeight);
        cursor.setBlockFormat(blockFormat);
    }

    QAbstractTextDocumentLayout::PaintContext ctx;
    ctx.palette.setColor(QPalette::Text, Qt::color1);

    doc.documentLayout()->draw(&p, ctx);

    p.end();

//    image->save("output.bmp");

    return { f2b::font::size_with_qsize(QSize(width, fm.lineSpacing())), std::move(image) };
}



================================================
FILE: app/qfontfacereader.h
================================================
#ifndef QFONTFACEREADER_H
#define QFONTFACEREADER_H

#include "fontdata.h"
#include <QFont>
#include <QImage>
#include <memory>
#include <utility>
#include <optional>

class QFontFaceReader : public f2b::font::face_reader
{
public:
    explicit QFontFaceReader(const QFont &font, std::string text = {}, std::optional<f2b::font::glyph_size> forced_size = {});
    virtual ~QFontFaceReader() override = default;

    virtual f2b::font::glyph_size font_size() const override { return sz_; }
    virtual std::size_t num_glyphs() const override { return num_glyphs_; }
    virtual bool is_pixel_set(std::size_t glyph_id, f2b::font::point p) const override;

private:
    static QString template_text(std::string text);
    static std::pair<f2b::font::glyph_size, std::unique_ptr<QImage>> read_font(
            const QFont &font, std::string text, std::optional<f2b::font::glyph_size> forcedSize);

    f2b::font::glyph_size sz_ { 0, 0 };
    std::unique_ptr<QImage> font_image_ { nullptr };
    std::size_t num_glyphs_ { 0 };
};

#endif // QFONTFACEREADER_H


================================================
FILE: app/semver.hpp
================================================
//          _____                            _   _
//         / ____|                          | | (_)
//        | (___   ___ _ __ ___   __ _ _ __ | |_ _  ___
//         \___ \ / _ \ '_ ` _ \ / _` | '_ \| __| |/ __|
//         ____) |  __/ | | | | | (_| | | | | |_| | (__
//        |_____/ \___|_| |_| |_|\__,_|_| |_|\__|_|\___|
// __      __           _             _                _____
// \ \    / /          (_)           (_)              / ____|_     _
//  \ \  / /__ _ __ ___ _  ___  _ __  _ _ __   __ _  | |   _| |_ _| |_
//   \ \/ / _ \ '__/ __| |/ _ \| '_ \| | '_ \ / _` | | |  |_   _|_   _|
//    \  /  __/ |  \__ \ | (_) | | | | | | | | (_| | | |____|_|   |_|
//     \/ \___|_|  |___/_|\___/|_| |_|_|_| |_|\__, |  \_____|
// https://github.com/Neargye/semver           __/ |
// version 0.2.2                              |___/
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2018 - 2020 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby  granted, free of charge, to any  person obtaining a copy
// of this software and associated  documentation files (the "Software"), to deal
// in the Software  without restriction, including without  limitation the rights
// to  use, copy,  modify, merge,  publish, distribute,  sublicense, and/or  sell
// copies  of  the Software,  and  to  permit persons  to  whom  the Software  is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE  IS PROVIDED "AS  IS", WITHOUT WARRANTY  OF ANY KIND,  EXPRESS OR
// IMPLIED,  INCLUDING BUT  NOT  LIMITED TO  THE  WARRANTIES OF  MERCHANTABILITY,
// FITNESS FOR  A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT  SHALL THE
// AUTHORS  OR COPYRIGHT  HOLDERS  BE  LIABLE FOR  ANY  CLAIM,  DAMAGES OR  OTHER
// LIABILITY, WHETHER IN AN ACTION OF  CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE  OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#ifndef NEARGYE_SEMANTIC_VERSIONING_HPP
#define NEARGYE_SEMANTIC_VERSIONING_HPP

#include <cstdint>
#include <cstddef>
#include <limits>
#include <iosfwd>
#include <optional>
#include <string>
#include <string_view>
#if __has_include(<charconv>)
#include <charconv>
#else
#include <system_error>
#endif

// Allow to disable exceptions.
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(SEMVER_NOEXCEPTION)
#  include <stdexcept>
#  define __SEMVER_THROW(exception) throw exception
#else
#  include <cstdlib>
#  define __SEMVER_THROW(exception) std::abort()
#endif

#if defined(__APPLE_CC__)
#  pragma clang diagnostic push
#  pragma clang diagnostic ignored "-Wmissing-braces" // Ignore warning: suggest braces around initialization of subobject 'return {first, std::errc::invalid_argument};'.
#endif

namespace semver {

enum struct prerelease : std::uint8_t {
  alpha = 0,
  beta = 1,
  rc = 2,
  none = 3
};

// Max version string length = 3(<major>) + 1(.) + 3(<minor>) + 1(.) + 3(<patch>) + 1(-) + 5(<prerelease>) + 1(.) + 3(<prereleaseversion>) = 21.
inline constexpr std::size_t max_version_string_length = 21;

namespace detail {

#if __has_include(<charconv>)
struct from_chars_result : std::from_chars_result {
  [[nodiscard]] constexpr operator bool() const noexcept { return ec == std::errc{}; }
};

struct to_chars_result : std::to_chars_result {
  [[nodiscard]] constexpr operator bool() const noexcept { return ec == std::errc{}; }
};
#else
struct from_chars_result {
  const char* ptr;
  std::errc ec;

  [[nodiscard]] constexpr operator bool() const noexcept { return ec == std::errc{}; }
};

struct to_chars_result {
  char* ptr;
  std::errc ec;

  [[nodiscard]] constexpr operator bool() const noexcept { return ec == std::errc{}; }
};
#endif

inline constexpr std::string_view alpha = {"-alpha", 6};
inline constexpr std::string_view beta  = {"-beta", 5};
inline constexpr std::string_view rc    = {"-rc", 3};

// Min version string length = 1(<major>) + 1(.) + 1(<minor>) + 1(.) + 1(<patch>) = 5.
inline constexpr auto min_version_string_length = 5;

constexpr char to_lower(char c) noexcept {
  return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
}

constexpr bool is_digit(char c) noexcept {
  return c >= '0' && c <= '9';
}

constexpr std::uint8_t to_digit(char c) noexcept {
  return c - '0';
}

constexpr std::uint8_t length(std::uint8_t x) noexcept {
  return x < 10 ? 1 : (x < 100 ? 2 : 3);
}

constexpr std::uint8_t length(prerelease t) noexcept {
  if (t == prerelease::alpha) {
    return 5;
  } else if (t == prerelease::beta) {
    return 4;
  } else if(t == prerelease::rc) {
    return 2;
  }

  return 0;
}

constexpr bool equals(const char* first, const char* last, std::string_view str) noexcept {
  for (std::size_t i = 0; first != last && i < str.length(); ++i, ++first) {
    if (to_lower(*first) != to_lower(str[i])) {
      return false;
    }
  }

  return true;
}

constexpr char* to_chars(char* str, std::uint8_t x, bool dot = true) noexcept {
  do {
    *(--str) = static_cast<char>('0' + (x % 10));
    x /= 10;
  } while (x != 0);

  if (dot) {
    *(--str) = '.';
  }

  return str;
}

constexpr char* to_chars(char* str, prerelease t) noexcept {
  const auto p = t == prerelease::alpha
                     ? alpha
                     : t == prerelease::beta
                           ? beta
                           : t == prerelease::rc
                                 ? rc
                                 : std::string_view{};

  for (auto it = p.rbegin(); it != p.rend(); ++it) {
    *(--str) = *it;
  }

  return str;
}

constexpr const char* from_chars(const char* first, const char* last, std::uint8_t& d) noexcept {
  if (first != last && is_digit(*first)) {
    std::int32_t t = 0;
    for (; first != last && is_digit(*first); ++first) {
      t = t * 10 + to_digit(*first);
    }
    if (t <= (std::numeric_limits<std::uint8_t>::max)()) {
      d = static_cast<std::uint8_t>(t);
      return first;
    }
  }

  return nullptr;
}

constexpr const char* from_chars(const char* first, const char* last, prerelease& p) noexcept {
  if (equals(first, last, alpha)) {
    p = prerelease::alpha;
    return first + alpha.length();
  } else if (equals(first, last, beta)) {
    p = prerelease::beta;
    return first + beta.length();
  } else if (equals(first, last, rc)) {
    p = prerelease::rc;
    return first + rc.length();
  }

  return nullptr;
}

constexpr bool check_delimiter(const char* first, const char* last, char d) noexcept {
  return first != last && first != nullptr && *first == d;
}

} // namespace semver::detail

struct version {
  std::uint8_t major             = 0;
  std::uint8_t minor             = 1;
  std::uint8_t patch             = 0;
  prerelease prerelease_type     = prerelease::none;
  std::uint8_t prerelease_number = 0;

  constexpr version(std::uint8_t major,
                    std::uint8_t minor,
                    std::uint8_t patch,
                    prerelease prerelease_type = prerelease::none,
                    std::uint8_t prerelease_number = 0) noexcept
      : major{major},
        minor{minor},
        patch{patch},
        prerelease_type{prerelease_type},
        prerelease_number{prerelease_type == prerelease::none ? static_cast<std::uint8_t>(0) : prerelease_number} {
  }

  explicit constexpr version(std::string_view str) : version(0, 0, 0, prerelease::none, 0) {
    from_string(str);
  }

  constexpr version() = default; // https://semver.org/#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase

  constexpr version(const version&) = default;

  constexpr version(version&&) = default;

  ~version() = default;

  version& operator=(const version&) = default;

  version& operator=(version&&) = default;

  [[nodiscard]] constexpr detail::from_chars_result from_chars(const char* first, const char* last) noexcept {
    if (first == nullptr || last == nullptr || (last - first) < detail::min_version_string_length) {
      return {first, std::errc::invalid_argument};
    }

    auto next = first;
    if (next = detail::from_chars(next, last, major); detail::check_delimiter(next, last, '.')) {
      if (next = detail::from_chars(++next, last, minor); detail::check_delimiter(next, last, '.')) {
        if (next = detail::from_chars(++next, last, patch); next == last) {
          prerelease_type = prerelease::none;
          prerelease_number = 0;
          return {next, std::errc{}};
        } else if (detail::check_delimiter(next, last, '-')) {
          if (next = detail::from_chars(next, last, prerelease_type); next == last) {
            prerelease_number = 0;
            return {next, std::errc{}};
          } else if (detail::check_delimiter(next, last, '.')) {
            if (next = detail::from_chars(++next, last, prerelease_number); next == last) {
              return {next, std::errc{}};
            }
          }
        }
      }
    }

    return {first, std::errc::invalid_argument};
  }

  [[nodiscard]] constexpr detail::to_chars_result to_chars(char* first, char* last) const noexcept {
    const auto length = chars_length();
    if (first == nullptr || last == nullptr || (last - first) < length) {
      return {last, std::errc::value_too_large};
    }

    auto next = first + length;
    if (prerelease_type != prerelease::none) {
      if (prerelease_number != 0) {
        next = detail::to_chars(next, prerelease_number);
      }
      next = detail::to_chars(next, prerelease_type);
    }
    next = detail::to_chars(next, patch);
    next = detail::to_chars(next, minor);
    next = detail::to_chars(next, major, false);

    return {first + length, std::errc{}};
  }

  [[nodiscard]] constexpr bool from_string_noexcept(std::string_view str) noexcept {
    return from_chars(str.data(), str.data() + str.length());
  }

  constexpr version& from_string(std::string_view str) {
    if (!from_string_noexcept(str)) {
      __SEMVER_THROW(std::invalid_argument{"semver::version::from_string invalid version."});
    }

    return *this;
  }

  [[nodiscard]] std::string to_string() const {
    auto str = std::string(chars_length(), '\0');
    if (!to_chars(str.data(), str.data() + str.length())) {
      __SEMVER_THROW(std::invalid_argument{"semver::version::to_string invalid version."});
    }

    return str;
  }

  [[nodiscard]] constexpr int compare(const version& other) const noexcept {
    if (major != other.major) {
      return major - other.major;
    }

    if (minor != other.minor) {
      return minor - other.minor;
    }

    if (patch != other.patch) {
      return patch - other.patch;
    }

    if (prerelease_type != other.prerelease_type) {
      return static_cast<std::uint8_t>(prerelease_type) - static_cast<std::uint8_t>(other.prerelease_type);
    }

    if (prerelease_number != other.prerelease_number) {
      return prerelease_number - other.prerelease_number;
    }

    return 0;
  }

 private:
  constexpr std::uint8_t chars_length() const noexcept {
    // (<major>) + 1(.) + (<minor>) + 1(.) + (<patch>)
    std::uint8_t length = detail::length(major) + detail::length(minor) + detail::length(patch) + 2;
    if (prerelease_type != prerelease::none) {
      // + 1(-) + (<prerelease>)
      length += detail::length(prerelease_type) + 1;
      if (prerelease_number != 0) {
        // + 1(.) + (<prereleaseversion>)
        length += detail::length(prerelease_number) + 1;
      }
    }
    return length;
  }
};

[[nodiscard]] constexpr bool operator==(const version& lhs, const version& rhs) noexcept {
  return lhs.compare(rhs) == 0;
}

[[nodiscard]] constexpr bool operator!=(const version& lhs, const version& rhs) noexcept {
  return lhs.compare(rhs) != 0;
}

[[nodiscard]] constexpr bool operator>(const version& lhs, const version& rhs) noexcept {
  return lhs.compare(rhs) > 0;
}

[[nodiscard]] constexpr bool operator>=(const version& lhs, const version& rhs) noexcept {
  return lhs.compare(rhs) >= 0;
}

[[nodiscard]] constexpr bool operator<(const version& lhs, const version& rhs) noexcept {
  return lhs.compare(rhs) < 0;
}

[[nodiscard]] constexpr bool operator<=(const version& lhs, const version& rhs) noexcept {
  return lhs.compare(rhs) <= 0;
}

[[nodiscard]] constexpr version operator""_version(const char* str, std::size_t length) {
  return version{std::string_view{str, length}};
}

[[nodiscard]] constexpr bool valid(std::string_view str) noexcept {
  return version{}.from_string_noexcept(str);
}

[[nodiscard]] constexpr detail::from_chars_result from_chars(const char* first, const char* last, version& v) noexcept {
  return v.from_chars(first, last);
}

[[nodiscard]] constexpr detail::to_chars_result to_chars(char* first, char* last, const version& v) noexcept {
  return v.to_chars(first, last);
}

[[nodiscard]] constexpr std::optional<version> from_string_noexcept(std::string_view str) noexcept {
  if (auto v = version{}; v.from_string_noexcept(str)) {
    return v;
  }

  return std::nullopt;
}

[[nodiscard]] constexpr version from_string(std::string_view str) {
  return version{str};
}

[[nodiscard]] inline std::string to_string(const version& v) {
  return v.to_string();
}

template <typename Char, typename Traits>
inline std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const version& v) {
  for (const auto c : v.to_string()) {
    os.put(c);
  }

  return os;
}

namespace ranges {

} // namespace semver::ranges

} // namespace semver

#if defined(__APPLE_CC__)
#  pragma clang diagnostic pop
#endif

#endif // NEARGYE_SEMANTIC_VERSIONING_HPP


================================================
FILE: app/sourcecoderunnable.cpp
================================================
#include "sourcecoderunnable.h"
#include <QElapsedTimer>
#include <QDebug>

void SourceCodeRunnable::run()
{
    QString output;

    QElapsedTimer timer;
    timer.start();
    if (format_ == f2b::format::arduino::identifier) {
        output = QString::fromStdString(generator_.gen
Download .txt
gitextract_t8uykv9z/

├── .gitignore
├── .gitmodules
├── CHANGELOG.md
├── CMakeLists.txt
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── app/
│   ├── CMakeLists.txt
│   ├── addglyphdialog.cpp
│   ├── addglyphdialog.h
│   ├── addglyphdialog.ui
│   ├── assets.qrc
│   ├── cmake_uninstall.cmake.in
│   ├── command.h
│   ├── common/
│   │   ├── CMakeLists.txt
│   │   ├── common.h
│   │   ├── f2b_qt_compat.cpp
│   │   └── f2b_qt_compat.h
│   ├── fontfaceviewmodel.cpp
│   ├── fontfaceviewmodel.h
│   ├── global.h
│   ├── l10n/
│   │   ├── fontedit_en.qm
│   │   └── fontedit_en.ts
│   ├── macos/
│   │   ├── Info.plist
│   │   └── fontedit.icns
│   ├── main.cpp
│   ├── mainwindow.cpp
│   ├── mainwindow.h
│   ├── mainwindow.ui
│   ├── mainwindowmodel.cpp
│   ├── mainwindowmodel.h
│   ├── qfontfacereader.cpp
│   ├── qfontfacereader.h
│   ├── semver.hpp
│   ├── sourcecoderunnable.cpp
│   ├── sourcecoderunnable.h
│   ├── ui/
│   │   ├── CMakeLists.txt
│   │   ├── aboutdialog.cpp
│   │   ├── aboutdialog.h
│   │   ├── aboutdialog.ui
│   │   ├── batchpixelchange.h
│   │   ├── facewidget.cpp
│   │   ├── facewidget.h
│   │   ├── focuswidget.cpp
│   │   ├── focuswidget.h
│   │   ├── glyphgraphicsview.cpp
│   │   ├── glyphgraphicsview.h
│   │   ├── glyphinfowidget.cpp
│   │   ├── glyphinfowidget.h
│   │   ├── glyphwidget.cpp
│   │   └── glyphwidget.h
│   ├── updatehelper.cpp
│   ├── updatehelper.h
│   ├── utf8/
│   │   ├── CMakeLists.txt
│   │   ├── utf8/
│   │   │   ├── checked.h
│   │   │   ├── core.h
│   │   │   └── unchecked.h
│   │   └── utf8.h
│   ├── win/
│   │   └── fontedit.rc
│   └── x11/
│       └── fontedit.desktop
├── fontedit.iss
├── lib/
│   ├── CMakeLists.txt
│   ├── src/
│   │   ├── CMakeLists.txt
│   │   ├── f2b.h
│   │   ├── fontdata.cpp
│   │   ├── fontdata.h
│   │   ├── fontsourcecodegenerator.cpp
│   │   ├── fontsourcecodegenerator.h
│   │   ├── format.h
│   │   ├── include/
│   │   │   └── f2b.h
│   │   └── sourcecode.h
│   └── test/
│       ├── CMakeLists.txt
│       ├── fontface_test.cpp
│       ├── glyph_test.cpp
│       └── sourcecode_test.cpp
└── test/
    ├── CMakeLists.txt
    ├── assets/
    │   ├── jetbrains260.fontedit
    │   ├── monaco8-subset.c-test
    │   ├── monaco8.c-test
    │   └── monaco8.fontedit
    ├── f2b_qt_compat_test.cpp
    └── sourcecodegeneration_test.cpp
Download .txt
SYMBOL INDEX (170 symbols across 42 files)

FILE: app/addglyphdialog.h
  function namespace (line 11) | namespace Ui {

FILE: app/command.h
  function undo (line 20) | void undo() override { undo_(); }
  function redo (line 21) | void redo() override { redo_(); }
  function undo (line 46) | void undo() override {
  function redo (line 51) | void redo() override {
  function mergeWith (line 62) | bool mergeWith(const QUndoCommand *other) override {
  function setToIndex (line 72) | void setToIndex(std::size_t index) {

FILE: app/common/common.h
  function namespace (line 6) | namespace Color {

FILE: app/common/f2b_qt_compat.cpp
  function QDataStream (line 11) | QDataStream& operator<<(QDataStream& s, const font::glyph& glyph)
  function QDataStream (line 23) | QDataStream& operator>>(QDataStream& s, font::glyph& glyph)
  function QDataStream (line 43) | QDataStream& operator<<(QDataStream& s, const font::face& face)
  function QDataStream (line 57) | QDataStream& operator>>(QDataStream& s, font::face& face)
  function QVariant (line 84) | QVariant to_qvariant(const source_code::indentation& i) {
  function from_qvariant (line 93) | source_code::indentation from_qvariant(const QVariant& v) {

FILE: app/common/f2b_qt_compat.h
  function namespace (line 18) | namespace f2b {

FILE: app/fontfaceviewmodel.cpp
  function import_face (line 15) | f2b::font::face import_face(const QFont &font)
  function QString (line 21) | QString font_name(const QFont &font)
  function FaceInfo (line 88) | FaceInfo FontFaceViewModel::faceInfo() const
  function QDataStream (line 180) | QDataStream& operator<<(QDataStream& s, const FontFaceViewModel &vm)
  function QDataStream (line 194) | QDataStream& operator>>(QDataStream& s, FontFaceViewModel& vm)

FILE: app/fontfaceviewmodel.h
  type FaceInfo (line 12) | struct FaceInfo
  function class (line 21) | class FontFaceViewModel
  function setGlyphExportedState (line 41) | void setGlyphExportedState(std::size_t idx, bool isExported) {
  function setActiveGlyphIndex (line 53) | void setActiveGlyphIndex(std::optional<std::size_t> idx) {
  function noexcept (line 60) | const noexcept {
  function resetActiveGlyph (line 71) | void resetActiveGlyph() {
  function isGlyphModified (line 91) | bool isGlyphModified(std::size_t idx) const {
  function isDirty_ (line 112) | bool isDirty_ { false };

FILE: app/global.h
  function namespace (line 6) | namespace Global {

FILE: app/main.cpp
  function main (line 7) | int main(int argc, char *argv[])

FILE: app/mainwindow.cpp
  function QString (line 318) | QString MainWindow::defaultDialogDirectory() const

FILE: app/mainwindow.h
  function namespace (line 18) | namespace Ui {
  function QString (line 74) | QString defaultDialogDirectory() const;

FILE: app/mainwindowmodel.cpp
  type SettingsKey (line 18) | namespace SettingsKey {
  function QString (line 295) | QString MainWindowModel::indentationStyleCaption() const
  function QString (line 317) | QString MainWindowModel::lastVisitedDirectory() const
  function QString (line 327) | QString MainWindowModel::lastSourceCodeDirectory() const

FILE: app/mainwindowmodel.h
  type UIState (line 17) | struct UIState {
  function class (line 57) | class MainWindowModel: public QObject
  function setFontArrayName (line 119) | void setFontArrayName(const QString& fontArrayName) {
  function QString (line 126) | QString lastVisitedDirectory() const;

FILE: app/qfontfacereader.cpp
  function QString (line 34) | QString QFontFaceReader::template_text(std::string text)

FILE: app/semver.hpp
  type semver (line 68) | namespace semver {
    type prerelease (line 70) | enum struct prerelease : std::uint8_t {
    type detail (line 80) | namespace detail {
      type from_chars_result (line 83) | struct from_chars_result : std::from_chars_result {
        method operator (line 84) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
        method operator (line 95) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
      type to_chars_result (line 87) | struct to_chars_result : std::to_chars_result {
        method operator (line 88) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
        method operator (line 102) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
      type from_chars_result (line 91) | struct from_chars_result {
        method operator (line 84) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
        method operator (line 95) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
      type to_chars_result (line 98) | struct to_chars_result {
        method operator (line 88) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
        method operator (line 102) | [[nodiscard]] constexpr operator bool() const noexcept { return ec...
      function to_lower (line 113) | constexpr char to_lower(char c) noexcept {
      function is_digit (line 117) | constexpr bool is_digit(char c) noexcept {
      function to_digit (line 121) | constexpr std::uint8_t to_digit(char c) noexcept {
      function length (line 125) | constexpr std::uint8_t length(std::uint8_t x) noexcept {
      function length (line 129) | constexpr std::uint8_t length(prerelease t) noexcept {
      function equals (line 141) | constexpr bool equals(const char* first, const char* last, std::stri...
      function check_delimiter (line 210) | constexpr bool check_delimiter(const char* first, const char* last, ...
    type version (line 216) | struct version {
      method version (line 223) | constexpr version(std::uint8_t major,
      method version (line 235) | explicit constexpr version(std::string_view str) : version(0, 0, 0, ...
      method version (line 239) | constexpr version() = default;
      method version (line 241) | constexpr version(const version&) = default;
      method version (line 243) | constexpr version(version&&) = default;
      method version (line 247) | version& operator=(const version&) = default;
      method version (line 249) | version& operator=(version&&) = default;
      method from_chars (line 251) | [[nodiscard]] constexpr detail::from_chars_result from_chars(const c...
      method to_chars (line 279) | [[nodiscard]] constexpr detail::to_chars_result to_chars(char* first...
      method from_string_noexcept (line 299) | [[nodiscard]] constexpr bool from_string_noexcept(std::string_view s...
      method version (line 303) | constexpr version& from_string(std::string_view str) {
      method to_string (line 311) | [[nodiscard]] std::string to_string() const {
      method compare (line 320) | [[nodiscard]] constexpr int compare(const version& other) const noex...
      method chars_length (line 345) | constexpr std::uint8_t chars_length() const noexcept {
    function version (line 384) | [[nodiscard]] constexpr version operator""_version(const char* str, st...
      method version (line 223) | constexpr version(std::uint8_t major,
      method version (line 235) | explicit constexpr version(std::string_view str) : version(0, 0, 0, ...
      method version (line 239) | constexpr version() = default;
      method version (line 241) | constexpr version(const version&) = default;
      method version (line 243) | constexpr version(version&&) = default;
      method version (line 247) | version& operator=(const version&) = default;
      method version (line 249) | version& operator=(version&&) = default;
      method from_chars (line 251) | [[nodiscard]] constexpr detail::from_chars_result from_chars(const c...
      method to_chars (line 279) | [[nodiscard]] constexpr detail::to_chars_result to_chars(char* first...
      method from_string_noexcept (line 299) | [[nodiscard]] constexpr bool from_string_noexcept(std::string_view s...
      method version (line 303) | constexpr version& from_string(std::string_view str) {
      method to_string (line 311) | [[nodiscard]] std::string to_string() const {
      method compare (line 320) | [[nodiscard]] constexpr int compare(const version& other) const noex...
      method chars_length (line 345) | constexpr std::uint8_t chars_length() const noexcept {
    function valid (line 388) | [[nodiscard]] constexpr bool valid(std::string_view str) noexcept {
    function from_chars (line 392) | [[nodiscard]] constexpr detail::from_chars_result from_chars(const cha...
    function to_chars (line 396) | [[nodiscard]] constexpr detail::to_chars_result to_chars(char* first, ...
    function from_string_noexcept (line 400) | [[nodiscard]] constexpr std::optional<version> from_string_noexcept(st...
    function version (line 408) | [[nodiscard]] constexpr version from_string(std::string_view str) {
      method version (line 223) | constexpr version(std::uint8_t major,
      method version (line 235) | explicit constexpr version(std::string_view str) : version(0, 0, 0, ...
      method version (line 239) | constexpr version() = default;
      method version (line 241) | constexpr version(const version&) = default;
      method version (line 243) | constexpr version(version&&) = default;
      method version (line 247) | version& operator=(const version&) = default;
      method version (line 249) | version& operator=(version&&) = default;
      method from_chars (line 251) | [[nodiscard]] constexpr detail::from_chars_result from_chars(const c...
      method to_chars (line 279) | [[nodiscard]] constexpr detail::to_chars_result to_chars(char* first...
      method from_string_noexcept (line 299) | [[nodiscard]] constexpr bool from_string_noexcept(std::string_view s...
      method version (line 303) | constexpr version& from_string(std::string_view str) {
      method to_string (line 311) | [[nodiscard]] std::string to_string() const {
      method compare (line 320) | [[nodiscard]] constexpr int compare(const version& other) const noex...
      method chars_length (line 345) | constexpr std::uint8_t chars_length() const noexcept {
    function to_string (line 412) | [[nodiscard]] inline std::string to_string(const version& v) {
    type ranges (line 425) | namespace ranges {

FILE: app/sourcecoderunnable.h
  function class (line 12) | class SourceCodeRunnable : public QRunnable
  function m_canceled (line 42) | bool m_canceled { false };

FILE: app/ui/aboutdialog.h
  function namespace (line 6) | namespace Ui {
  function class (line 10) | class AboutDialog : public QDialog

FILE: app/ui/batchpixelchange.h
  type PointHash (line 9) | struct PointHash {
  type BatchPixelChange (line 15) | struct BatchPixelChange {
  function add (line 22) | void add(const f2b::font::point &pixel, bool value) {

FILE: app/ui/facewidget.cpp
  function QSizeF (line 39) | QSizeF FaceWidget::calculateImageSize(f2b::font::glyph_size glyph_size)
  function GlyphInfoWidget (line 155) | GlyphInfoWidget* FaceWidget::glyphWidgetAtIndex(std::size_t index)
  function QSize (line 169) | QSize FaceWidget::glyphCoordsAtPos(QPointF pos)
  function GlyphInfoWidget (line 179) | GlyphInfoWidget* FaceWidget::glyphWidgetAtPos(QPointF pos)

FILE: app/ui/facewidget.h
  function f2b (line 61) | const f2b::font::face* face_ { nullptr };

FILE: app/ui/focuswidget.h
  function class (line 8) | class FocusWidget : public QGraphicsWidget

FILE: app/ui/glyphgraphicsview.h
  function class (line 10) | class GlyphGraphicsView : public QGraphicsView

FILE: app/ui/glyphinfowidget.cpp
  function QString (line 13) | static QString description(unsigned char asciiCode)

FILE: app/ui/glyphinfowidget.h
  function class (line 11) | class GlyphInfoWidget : public QGraphicsWidget

FILE: app/ui/glyphwidget.cpp
  function QRectF (line 14) | QRectF rectForPoint(const f2b::font::point& point)
  function QRectF (line 40) | QRectF GlyphWidget::boundingRect() const

FILE: app/ui/glyphwidget.h
  function QRectF (line 26) | QRectF boundingRect() const override;
  function penState_ (line 58) | bool penState_ { false };

FILE: app/updatehelper.cpp
  type SettingsKey (line 7) | namespace SettingsKey {

FILE: app/updatehelper.h
  type Update (line 13) | struct Update {
  function isChecking_ (line 37) | bool isChecking_ { false };

FILE: app/utf8/utf8/checked.h
  function namespace (line 34) | namespace utf8
  function output_iterator (line 130) | output_iterator replace_invalid(octet_iterator start, octet_iterator end...
  function operator (line 284) | uint32_t operator * () const
  function operator (line 295) | bool operator != (const iterator& rhs) const
  function iterator (line 304) | iterator operator ++ (int)
  function iterator (line 315) | iterator operator -- (int)

FILE: app/utf8/utf8/core.h
  function namespace (line 33) | namespace utf8

FILE: app/utf8/utf8/unchecked.h
  function namespace (line 33) | namespace utf8

FILE: lib/src/fontdata.cpp
  type f2b (line 4) | namespace f2b {
    type font (line 6) | namespace font {
      function margins (line 80) | margins face::calculate_margins() const noexcept

FILE: lib/src/fontdata.h
  function namespace (line 8) | namespace f2b {
  function else (line 33) | struct glyph_size
  type point (line 61) | struct point
  function class (line 82) | class glyph
  function class (line 117) | class face_reader

FILE: lib/src/fontsourcecodegenerator.cpp
  type f2b (line 5) | namespace f2b {
    function pixel_margins (line 7) | font::margins pixel_margins(font::margins line_margins, font::glyph_si...

FILE: lib/src/fontsourcecodegenerator.h
  type source_code_options (line 18) | struct source_code_options
  function invert_bits (line 26) | bool invert_bits { false };
  function V (line 249) | V exported_id { static_cast<V>(has_dummy_blank_glyph) };

FILE: lib/src/format.h
  function namespace (line 9) | namespace f2b
  function else (line 139) | else if constexpr (std::is_same<V, int16_t>::value) {
  function else (line 141) | else if constexpr (std::is_same<V, int32_t>::value) {
  function else (line 153) | else if constexpr (std::is_same<V, int16_t>::value) {
  function else (line 155) | else if constexpr (std::is_same<V, int32_t>::value) {
  function else (line 161) | else if constexpr (is_python<T>::value) {
  function else (line 183) | else if constexpr (std::is_same<V, uint32_t>::value) {
  function else (line 185) | else if constexpr (std::is_same<V, uint64_t>::value) {
  function else (line 187) | else if constexpr (std::is_same<V, int8_t>::value) {
  function else (line 189) | else if constexpr (std::is_same<V, int16_t>::value) {
  function else (line 191) | else if constexpr (std::is_same<V, int32_t>::value) {
  function else (line 193) | else if constexpr (std::is_same<V, int64_t>::value) {
  function else (line 205) | else if constexpr (std::is_same<V, uint32_t>::value) {
  function else (line 207) | else if constexpr (std::is_same<V, uint64_t>::value) {
  function else (line 209) | else if constexpr (std::is_same<V, int8_t>::value) {
  function else (line 211) | else if constexpr (std::is_same<V, int16_t>::value) {
  function else (line 213) | else if constexpr (std::is_same<V, int32_t>::value) {
  function else (line 215) | else if constexpr (std::is_same<V, int64_t>::value) {
  function else (line 221) | else if constexpr (std::is_same<T, format::python_list>::value) {
  function else (line 225) | else if constexpr (std::is_same<T, format::python_bytes>::value) {

FILE: lib/src/sourcecode.h
  function namespace (line 9) | namespace f2b  {

FILE: lib/test/fontface_test.cpp
  class TestFaceData (line 6) | class TestFaceData : public font::face_reader
    method font_size (line 9) | font::glyph_size font_size() const override { return { 4, 3 }; }
    method num_glyphs (line 10) | std::size_t num_glyphs() const override { return 5; }
    method is_pixel_set (line 12) | bool is_pixel_set(std::size_t glyph_id, font::point p) const override
  function TEST (line 43) | TEST(FaceTest, Initialization)

FILE: lib/test/glyph_test.cpp
  function TEST (line 6) | TEST(GlyphTest, API)

FILE: lib/test/sourcecode_test.cpp
  function TEST (line 4) | TEST(SourceCodeTest, IdiomTraits)

FILE: test/f2b_qt_compat_test.cpp
  function serialize_and_deserialize (line 17) | void serialize_and_deserialize(const T& input, T& output)
  function TEST (line 32) | TEST(SerializationTest, optional_int)
  function TEST (line 46) | TEST(SerializationTest, optional_qstring)
  function TEST (line 57) | TEST(SerializationTest, vector_bool)
  function TEST (line 73) | TEST(SerializationTest, set_size_t)
  function TEST (line 89) | TEST(SerializationTest, unordered_map_int_qstring)
  function TEST (line 109) | TEST(SerializationTest, font_glyph)
  function TEST (line 119) | TEST(SerializationTest, font_face)

FILE: test/sourcecodegeneration_test.cpp
  function QString (line 17) | QString asset(const T& fileName)
  class test_source_code_generator (line 22) | class test_source_code_generator : public font_source_code_generator
    method test_source_code_generator (line 25) | test_source_code_generator(source_code_options options): font_source_c...
    method current_timestamp (line 27) | std::string current_timestamp() override {
  function TEST (line 32) | TEST(SourceCodeGeneratorTest, GeneratorAll)
  function TEST (line 61) | TEST(SourceCodeGeneratorTest, GeneratorSubset)
  function TEST (line 91) | TEST(SourceCodeGeneratorTest, GeneratorPerformance)
Condensed preview — 82 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (360K chars).
[
  {
    "path": ".gitignore",
    "chars": 484,
    "preview": "# C++ objects and libs\n*.slo\n*.lo\n*.o\n*.a\n*.la\n*.lai\n*.so\n*.dll\n*.dylib\n\n# Qt-es\nobject_script.*.Release\nobject_script.*"
  },
  {
    "path": ".gitmodules",
    "chars": 156,
    "preview": "[submodule \"gsl\"]\n\tpath = gsl\n\turl = https://github.com/microsoft/GSL.git\n[submodule \"gtest\"]\n\tpath = gtest\n\turl = https"
  },
  {
    "path": "CHANGELOG.md",
    "chars": 724,
    "preview": "# Changelog\n\n## 1.1.0 - 2020-05-31\n* Export subset of font characters (only the characters that you really\n  need in the"
  },
  {
    "path": "CMakeLists.txt",
    "chars": 1765,
    "preview": "cmake_minimum_required(VERSION 3.9)\nproject(FontEdit)\n\nset(CMAKE_PROJECT_VERSION_MAJOR 1)\nset(CMAKE_PROJECT_VERSION_MINO"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "chars": 3350,
    "preview": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, w"
  },
  {
    "path": "LICENSE",
    "chars": 35148,
    "preview": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
  },
  {
    "path": "README.md",
    "chars": 3780,
    "preview": "# FontEdit\n\nFontEdit is a desktop application that allows you to convert general-purpose \nfixed-width desktop fonts to b"
  },
  {
    "path": "app/CMakeLists.txt",
    "chars": 3363,
    "preview": "cmake_minimum_required(VERSION 3.9)\n\nif (UNIX AND NOT APPLE)\n    project(fontedit LANGUAGES CXX)\nelse()\n    project(Font"
  },
  {
    "path": "app/addglyphdialog.cpp",
    "chars": 2008,
    "preview": "#include \"addglyphdialog.h\"\n#include \"./ui_addglyphdialog.h\"\n#include \"facewidget.h\"\n#include \"qfontfacereader.h\"\n\nAddGl"
  },
  {
    "path": "app/addglyphdialog.h",
    "chars": 752,
    "preview": "#ifndef ADDGLYPHDIALOG_H\n#define ADDGLYPHDIALOG_H\n\n#include <QDialog>\n#include <QGraphicsScene>\n#include <memory>\n#inclu"
  },
  {
    "path": "app/addglyphdialog.ui",
    "chars": 4501,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>AddGlyphDialog</class>\n <widget class=\"QDialog\" name=\""
  },
  {
    "path": "app/assets.qrc",
    "chars": 950,
    "preview": "<RCC>\n    <qresource prefix=\"/toolbar\">\n        <file>assets/code.svg</file>\n        <file>assets/copy.svg</file>\n      "
  },
  {
    "path": "app/cmake_uninstall.cmake.in",
    "chars": 1003,
    "preview": "if(NOT EXISTS \"@CMAKE_BINARY_DIR@/install_manifest.txt\")\n  message(FATAL_ERROR \"Cannot find install manifest: @CMAKE_BIN"
  },
  {
    "path": "app/command.h",
    "chars": 2061,
    "preview": "#ifndef COMMAND_H\n#define COMMAND_H\n\n#include <QUndoCommand>\n#include \"facewidget.h\"\n#include \"mainwindowmodel.h\"\n\nclass"
  },
  {
    "path": "app/common/CMakeLists.txt",
    "chars": 413,
    "preview": "cmake_minimum_required(VERSION 3.9)\n\nset(CMAKE_AUTOUIC OFF)\nset(CMAKE_AUTOMOC OFF)\nset(CMAKE_AUTORCC OFF)\n\nproject(commo"
  },
  {
    "path": "app/common/common.h",
    "chars": 512,
    "preview": "#ifndef COMMON_H\n#define COMMON_H\n\n#include <QRgb>\n\nnamespace Color {\n\nstatic constexpr QRgb activeGlyph = 0xff000000;\ns"
  },
  {
    "path": "app/common/f2b_qt_compat.cpp",
    "chars": 2759,
    "preview": "#include \"f2b_qt_compat.h\"\n\nstatic constexpr quint32 font_glyph_magic_number = 0x92588c12;\nstatic constexpr quint32 font"
  },
  {
    "path": "app/common/f2b_qt_compat.h",
    "chars": 7850,
    "preview": "#ifndef F2B_QT_COMPAT_H\n#define F2B_QT_COMPAT_H\n\n#include \"f2b.h\"\n#include <QPoint>\n#include <QSize>\n#include <QBitmap>\n"
  },
  {
    "path": "app/fontfaceviewmodel.cpp",
    "chars": 5651,
    "preview": "#include \"fontfaceviewmodel.h\"\n#include \"f2b.h\"\n#include \"f2b_qt_compat.h\"\n#include \"qfontfacereader.h\"\n\n#include <utili"
  },
  {
    "path": "app/fontfaceviewmodel.h",
    "chars": 3769,
    "preview": "#ifndef FONTFACEVIEWMODEL_H\n#define FONTFACEVIEWMODEL_H\n\n#include <QFont>\n#include \"f2b.h\"\n#include <optional>\n#include "
  },
  {
    "path": "app/global.h",
    "chars": 331,
    "preview": "#ifndef GLOBAL_H\n#define GLOBAL_H\n\n#include <QString>\n\nnamespace Global {\nstatic const QString organization_name = \"Domi"
  },
  {
    "path": "app/l10n/fontedit_en.ts",
    "chars": 19887,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE TS>\n<TS version=\"2.1\" language=\"en_US\">\n<context>\n    <name>AboutDialog"
  },
  {
    "path": "app/macos/Info.plist",
    "chars": 1234,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.c"
  },
  {
    "path": "app/main.cpp",
    "chars": 705,
    "preview": "#include \"mainwindow.h\"\n#include \"global.h\"\n\n#include <QApplication>\n#include <QtGui>\n\nint main(int argc, char *argv[])\n"
  },
  {
    "path": "app/mainwindow.cpp",
    "chars": 29854,
    "preview": "#include \"mainwindow.h\"\n#include \"./ui_mainwindow.h\"\n#include \"f2b.h\"\n#include \"facewidget.h\"\n#include \"fontfaceviewmode"
  },
  {
    "path": "app/mainwindow.h",
    "chars": 2627,
    "preview": "#ifndef MAINWINDOW_H\n#define MAINWINDOW_H\n\n#include <QMainWindow>\n#include <QGraphicsScene>\n#include <QUndoStack>\n#inclu"
  },
  {
    "path": "app/mainwindow.ui",
    "chars": 23184,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>MainWindow</class>\n <widget class=\"QMainWindow\" name=\""
  },
  {
    "path": "app/mainwindowmodel.cpp",
    "chars": 12941,
    "preview": "#include \"mainwindowmodel.h\"\n#include \"sourcecoderunnable.h\"\n#include \"f2b_qt_compat.h\"\n#include <f2b.h>\n\n#include <QDeb"
  },
  {
    "path": "app/mainwindowmodel.h",
    "chars": 5523,
    "preview": "#ifndef MAINWINDOWMODEL_H\n#define MAINWINDOWMODEL_H\n\n#include \"fontfaceviewmodel.h\"\n#include <f2b.h>\n#include <memory>\n#"
  },
  {
    "path": "app/qfontfacereader.cpp",
    "chars": 3504,
    "preview": "#include \"qfontfacereader.h\"\n#include \"f2b_qt_compat.h\"\n\n#include <QAbstractTextDocumentLayout>\n#include <QFontMetrics>\n"
  },
  {
    "path": "app/qfontfacereader.h",
    "chars": 1054,
    "preview": "#ifndef QFONTFACEREADER_H\n#define QFONTFACEREADER_H\n\n#include \"fontdata.h\"\n#include <QFont>\n#include <QImage>\n#include <"
  },
  {
    "path": "app/semver.hpp",
    "chars": 13736,
    "preview": "//          _____                            _   _\n//         / ____|                          | | (_)\n//        | (___ "
  },
  {
    "path": "app/sourcecoderunnable.cpp",
    "chars": 1459,
    "preview": "#include \"sourcecoderunnable.h\"\n#include <QElapsedTimer>\n#include <QDebug>\n\nvoid SourceCodeRunnable::run()\n{\n    QString"
  },
  {
    "path": "app/sourcecoderunnable.h",
    "chars": 1237,
    "preview": "#ifndef SOURCECODERUNNABLE_H\n#define SOURCECODERUNNABLE_H\n\n#include <QRunnable>\n#include <QString>\n#include <f2b.h>\n#inc"
  },
  {
    "path": "app/ui/CMakeLists.txt",
    "chars": 501,
    "preview": "cmake_minimum_required(VERSION 3.9)\n\nproject(ui LANGUAGES CXX)\n\nfind_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)\n\n"
  },
  {
    "path": "app/ui/aboutdialog.cpp",
    "chars": 2209,
    "preview": "#include \"aboutdialog.h\"\n#include \"./ui_aboutdialog.h\"\n#include <QIcon>\n#include <QDesktopServices>\n#include <QUrl>\n\nsta"
  },
  {
    "path": "app/ui/aboutdialog.h",
    "chars": 297,
    "preview": "#ifndef ABOUTDIALOG_H\n#define ABOUTDIALOG_H\n\n#include <QDialog>\n\nnamespace Ui {\nclass AboutDialog;\n}\n\nclass AboutDialog "
  },
  {
    "path": "app/ui/aboutdialog.ui",
    "chars": 6701,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>AboutDialog</class>\n <widget class=\"QDialog\" name=\"Abo"
  },
  {
    "path": "app/ui/batchpixelchange.h",
    "chars": 991,
    "preview": "#ifndef GLYPHEDITCOMMAND_H\n#define GLYPHEDITCOMMAND_H\n\n#include <unordered_map>\n#include <memory>\n#include <functional>\n"
  },
  {
    "path": "app/ui/facewidget.cpp",
    "chars": 8845,
    "preview": "#include \"facewidget.h\"\n#include \"glyphinfowidget.h\"\n#include \"f2b_qt_compat.h\"\n\n#include <QGraphicsSceneEvent>\n#include"
  },
  {
    "path": "app/ui/facewidget.h",
    "chars": 2110,
    "preview": "#ifndef FACEWIDGET_H\n#define FACEWIDGET_H\n\n#include <QGraphicsWidget>\n#include <QGraphicsGridLayout>\n#include <f2b.h>\n#i"
  },
  {
    "path": "app/ui/focuswidget.cpp",
    "chars": 949,
    "preview": "#include \"focuswidget.h\"\n#include <QPainter>\n#include <QDebug>\n#include <QGraphicsScene>\n#include <QGraphicsView>\n\nFocus"
  },
  {
    "path": "app/ui/focuswidget.h",
    "chars": 649,
    "preview": "#ifndef FOCUSWIDGET_H\n#define FOCUSWIDGET_H\n\n#include <QGraphicsWidget>\n\nclass QGraphicsLayoutItem;\n\nclass FocusWidget :"
  },
  {
    "path": "app/ui/glyphgraphicsview.cpp",
    "chars": 1913,
    "preview": "#include \"glyphgraphicsview.h\"\n#include <QTouchEvent>\n#include <QDebug>\n#include <QTimeLine>\n#include <cmath>\n#include \""
  },
  {
    "path": "app/ui/glyphgraphicsview.h",
    "chars": 492,
    "preview": "#ifndef GLYPHGRAPHICSVIEW_H\n#define GLYPHGRAPHICSVIEW_H\n\n#include <QGraphicsView>\n#include <optional>\n#include \"f2b.h\"\n\n"
  },
  {
    "path": "app/ui/glyphinfowidget.cpp",
    "chars": 3740,
    "preview": "#include \"glyphinfowidget.h\"\n#include \"f2b_qt_compat.h\"\n#include \"common.h\"\n\n#include <QPainter>\n#include <QDebug>\n#incl"
  },
  {
    "path": "app/ui/glyphinfowidget.h",
    "chars": 1348,
    "preview": "#ifndef GLYPHINFOWIDGET_H\n#define GLYPHINFOWIDGET_H\n\n#include <QGraphicsWidget>\n#include <QImage>\n#include <QAction>\n#in"
  },
  {
    "path": "app/ui/glyphwidget.cpp",
    "chars": 8318,
    "preview": "#include \"glyphwidget.h\"\n#include \"common.h\"\n#include <QPainter>\n#include <QDebug>\n#include <QGraphicsSceneMouseEvent>\n#"
  },
  {
    "path": "app/ui/glyphwidget.h",
    "chars": 1929,
    "preview": "#ifndef RAWGLYPHWIDGET_H\n#define RAWGLYPHWIDGET_H\n\n#include <QGraphicsWidget>\n#include <f2b.h>\n#include <memory>\n#includ"
  },
  {
    "path": "app/updatehelper.cpp",
    "chars": 3113,
    "preview": "#include \"updatehelper.h\"\n#include <QtNetwork>\n#include <QJsonDocument>\n#include <QApplication>\n#include \"semver.hpp\"\n\nn"
  },
  {
    "path": "app/updatehelper.h",
    "chars": 894,
    "preview": "#ifndef UPDATEHELPER_H\n#define UPDATEHELPER_H\n\n#include <QObject>\n#include <QtNetwork>\n#include <memory>\n\nclass UpdateHe"
  },
  {
    "path": "app/utf8/CMakeLists.txt",
    "chars": 266,
    "preview": "cmake_minimum_required(VERSION 3.9)\n\nset(CMAKE_AUTOUIC OFF)\nset(CMAKE_AUTOMOC OFF)\nset(CMAKE_AUTORCC OFF)\n\nproject(utf8 "
  },
  {
    "path": "app/utf8/utf8/checked.h",
    "chars": 12172,
    "preview": "// Copyright 2006 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobt"
  },
  {
    "path": "app/utf8/utf8/core.h",
    "chars": 10697,
    "preview": "// Copyright 2006 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobt"
  },
  {
    "path": "app/utf8/utf8/unchecked.h",
    "chars": 8907,
    "preview": "// Copyright 2006 Nemanja Trifunovic\n\n/*\nPermission is hereby granted, free of charge, to any person or organization\nobt"
  },
  {
    "path": "app/utf8/utf8.h",
    "chars": 1555,
    "preview": "// Copyright 2006 Nemanja Trifunovic\r\n\r\n/*\r\nPermission is hereby granted, free of charge, to any person or organization\r"
  },
  {
    "path": "app/win/fontedit.rc",
    "chars": 47,
    "preview": "IDI_ICON1               ICON    \"fontedit.ico\"\n"
  },
  {
    "path": "app/x11/fontedit.desktop",
    "chars": 197,
    "preview": "[Desktop Entry]\nExec=fontedit\nName=FontEdit\nIcon=fontedit\nType=Application\nCategories=Qt;Development;\nComment=Font image"
  },
  {
    "path": "fontedit.iss",
    "chars": 2098,
    "preview": "; Script generated by the Inno Setup Script Wizard.\n; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FI"
  },
  {
    "path": "lib/CMakeLists.txt",
    "chars": 301,
    "preview": "cmake_minimum_required(VERSION 3.9)\nproject(libFontEdit)\n\nset(LIBFONTEDIT_STANDALONE_PROJECT OFF)\nif (CMAKE_CURRENT_SOUR"
  },
  {
    "path": "lib/src/CMakeLists.txt",
    "chars": 1085,
    "preview": "cmake_minimum_required(VERSION 3.9)\n\nset(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\n\nproject(font2bytes)"
  },
  {
    "path": "lib/src/f2b.h",
    "chars": 173,
    "preview": "#ifndef F2B_PRIVATE_H\n#define F2B_PRIVATE_H\n\n#include \"fontdata.h\"\n#include \"fontsourcecodegenerator.h\"\n#include \"format"
  },
  {
    "path": "lib/src/fontdata.cpp",
    "chars": 2494,
    "preview": "#include \"fontdata.h\"\n#include <algorithm>\n\nnamespace f2b {\n\nnamespace font {\n\nglyph::glyph(font::glyph_size sz) :\n    s"
  },
  {
    "path": "lib/src/fontdata.h",
    "chars": 6025,
    "preview": "#ifndef FONTDATA_H\n#define FONTDATA_H\n\n#include <vector>\n#include <iostream>\n#include <set>\n\nnamespace f2b {\n\nnamespace "
  },
  {
    "path": "lib/src/fontsourcecodegenerator.cpp",
    "chars": 883,
    "preview": "#include \"fontsourcecodegenerator.h\"\n#include <iomanip>\n#include <string>\n\nnamespace f2b {\n\nfont::margins pixel_margins("
  },
  {
    "path": "lib/src/fontsourcecodegenerator.h",
    "chars": 12399,
    "preview": "#ifndef FONTSOURCECODEGENERATOR_H\n#define FONTSOURCECODEGENERATOR_H\n\n#include \"fontdata.h\"\n#include \"sourcecode.h\"\n#incl"
  },
  {
    "path": "lib/src/format.h",
    "chars": 10219,
    "preview": "#ifndef FORMAT_H\n#define FORMAT_H\n\n#include <string>\n#include <iostream>\n#include <iomanip>\n#include \"sourcecode.h\"\n\nnam"
  },
  {
    "path": "lib/src/include/f2b.h",
    "chars": 67,
    "preview": "#ifndef F2B_H\n#define F2B_H\n\n#include \"f2b/f2b.h\"\n\n#endif // F2B_H\n"
  },
  {
    "path": "lib/src/sourcecode.h",
    "chars": 2596,
    "preview": "#ifndef SOURCECODE_H\n#define SOURCECODE_H\n\n#include \"fontdata.h\"\n#include <string>\n#include <iostream>\n#include <variant"
  },
  {
    "path": "lib/test/CMakeLists.txt",
    "chars": 548,
    "preview": "\ncmake_minimum_required(VERSION 3.9)\n\nset(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\n\nset(UNIT_TEST_LIST"
  },
  {
    "path": "lib/test/fontface_test.cpp",
    "chars": 1712,
    "preview": "#include \"gtest/gtest.h\"\n#include \"fontdata.h\"\n\nusing namespace f2b;\n\nclass TestFaceData : public font::face_reader\n{\npu"
  },
  {
    "path": "lib/test/glyph_test.cpp",
    "chars": 173,
    "preview": "#include \"gtest/gtest.h\"\n#include \"fontdata.h\"\n\nusing namespace f2b;\n\nTEST(GlyphTest, API)\n{\n    font::glyph_size sz { 5"
  },
  {
    "path": "lib/test/sourcecode_test.cpp",
    "chars": 65,
    "preview": "#include \"gtest/gtest.h\"\n\n\nTEST(SourceCodeTest, IdiomTraits)\n{\n}\n"
  },
  {
    "path": "test/CMakeLists.txt",
    "chars": 571,
    "preview": "cmake_minimum_required(VERSION 3.9)\n\nset(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\n\nfind_package(Qt5 CO"
  },
  {
    "path": "test/assets/monaco8-subset.c-test",
    "chars": 10788,
    "preview": "//\n// font\n// Font Size: 5x8px\n// Created: <timestamp>\n//\n\n#include <stdint.h>\n\n// \n// Pseudocode for retrieving data fo"
  },
  {
    "path": "test/assets/monaco8.c-test",
    "chars": 7040,
    "preview": "//\n// font\n// Font Size: 5x8px\n// Created: <timestamp>\n//\n\n#include <stdint.h>\n\n// \n// Pseudocode for retrieving data fo"
  },
  {
    "path": "test/f2b_qt_compat_test.cpp",
    "chars": 3038,
    "preview": "#include \"gtest/gtest.h\"\n#include \"f2b_qt_compat.h\"\n\n#include <optional>\n#include <vector>\n#include <set>\n#include <unor"
  },
  {
    "path": "test/sourcecodegeneration_test.cpp",
    "chars": 3740,
    "preview": "#include \"gtest/gtest.h\"\n#include \"fontsourcecodegenerator.h\"\n#include \"fontfaceviewmodel.h\"\n#include <gsl/gsl>\n\n#includ"
  }
]

// ... and 4 more files (download for full content)

About this extraction

This page contains the full source code of the ayoy/fontedit GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 82 files (335.1 KB), approximately 93.0k tokens, and a symbol index with 170 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!