Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Adobe OpenType-SVG format support #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/img/sample2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,62 @@ set(SOURCES
src/external/maxRectsBinPack/Rect.h
src/external/lodepng/lodepng.h
src/external/lodepng/lodepng.cpp
src/external/lunasvg/include/lunasvg.h
src/external/lunasvg/source/canvas.cpp
src/external/lunasvg/source/canvas.h
src/external/lunasvg/source/clippathelement.cpp
src/external/lunasvg/source/clippathelement.h
src/external/lunasvg/source/defselement.cpp
src/external/lunasvg/source/defselement.h
src/external/lunasvg/source/element.cpp
src/external/lunasvg/source/element.h
src/external/lunasvg/source/gelement.cpp
src/external/lunasvg/source/gelement.h
src/external/lunasvg/source/geometryelement.cpp
src/external/lunasvg/source/geometryelement.h
src/external/lunasvg/source/graphicselement.cpp
src/external/lunasvg/source/graphicselement.h
src/external/lunasvg/source/layoutcontext.cpp
src/external/lunasvg/source/layoutcontext.h
src/external/lunasvg/source/lunasvg.cpp
src/external/lunasvg/source/markerelement.cpp
src/external/lunasvg/source/markerelement.h
src/external/lunasvg/source/maskelement.cpp
src/external/lunasvg/source/maskelement.h
src/external/lunasvg/source/paintelement.cpp
src/external/lunasvg/source/paintelement.h
src/external/lunasvg/source/parser.cpp
src/external/lunasvg/source/parser.h
src/external/lunasvg/source/parserutils.h
src/external/lunasvg/source/property.cpp
src/external/lunasvg/source/property.h
src/external/lunasvg/source/stopelement.cpp
src/external/lunasvg/source/stopelement.h
src/external/lunasvg/source/styledelement.cpp
src/external/lunasvg/source/styledelement.h
src/external/lunasvg/source/styleelement.cpp
src/external/lunasvg/source/styleelement.h
src/external/lunasvg/source/svgelement.cpp
src/external/lunasvg/source/svgelement.h
src/external/lunasvg/source/symbolelement.cpp
src/external/lunasvg/source/symbolelement.h
src/external/lunasvg/source/useelement.cpp
src/external/lunasvg/source/useelement.h
src/external/lunasvg/3rdparty/plutovg/plutovg-blend.c
src/external/lunasvg/3rdparty/plutovg/plutovg.c
src/external/lunasvg/3rdparty/plutovg/plutovg-dash.c
src/external/lunasvg/3rdparty/plutovg/plutovg-ft-math.c
src/external/lunasvg/3rdparty/plutovg/plutovg-ft-math.h
src/external/lunasvg/3rdparty/plutovg/plutovg-ft-raster.c
src/external/lunasvg/3rdparty/plutovg/plutovg-ft-raster.h
src/external/lunasvg/3rdparty/plutovg/plutovg-ft-stroker.c
src/external/lunasvg/3rdparty/plutovg/plutovg-ft-stroker.h
src/external/lunasvg/3rdparty/plutovg/plutovg-ft-types.h
src/external/lunasvg/3rdparty/plutovg/plutovg-geometry.c
src/external/lunasvg/3rdparty/plutovg/plutovg.h
src/external/lunasvg/3rdparty/plutovg/plutovg-paint.c
src/external/lunasvg/3rdparty/plutovg/plutovg-private.h
src/external/lunasvg/3rdparty/plutovg/plutovg-rle.c
)

add_definitions(-DLODEPNG_NO_COMPILE_DECODER)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# fontbm

[BMFont](http://www.angelcode.com/products/bmfont/) compatible, cross-platform (Linux/macOS/Windows) command line bitmap font generator (FreeType2 based render).
[BMFont](http://www.angelcode.com/products/bmfont/) compatible, cross-platform (Linux/macOS/Windows) command line bitmap font generator (FreeType2 based renderer) including the Adobe OpenType-SVG format.

![sample](/.github/img/sample0.png?raw=true)
![sample](/.github/img/sample1.png?raw=true)
![sample](/.github/img/sample2.png?raw=true)

## Status

Expand Down Expand Up @@ -55,6 +56,7 @@ Dependencies:
* GCC-4.9
* CMake 3.0
* [FreeType](https://www.freetype.org/)
* [LunaSVG](https://github.com/sammycage/lunasvg)

Build:

Expand Down Expand Up @@ -101,6 +103,7 @@ make
* [cherniid](https://github.com/cherniid)
* [Radfordhound](https://github.com/Radfordhound)
* [phoddie](https://github.com/phoddie)
* [benbaker76](https://github.com/benbaker76)

## Special thanks

Expand All @@ -118,3 +121,4 @@ The project also bundles third party software under its own licenses:
* [catchorg/Catch2](https://github.com/catchorg/Catch2) - A modern, C++-native, header-only, test framework for unit-tests - [BSL-1.0](https://github.com/catchorg/Catch2/blob/master/LICENSE.txt)
* [jarro2783/cxxopts](https://github.com/jarro2783/cxxopts) - Lightweight C++ command line option parser - [MIT](https://github.com/jarro2783/cxxopts/blob/master/LICENSE)
* [nlohmann/json](https://github.com/nlohmann/json) - JSON for Modern C++ - [MIT](https://github.com/nlohmann/json/blob/develop/LICENSE.MIT)
* [sammycage/lunasvg](https://github.com/sammycage/lunasvg) - SVG rendering library in C++ - [MIT](https://github.com/sammycage/lunasvg/blob/master/LICENSE)
27 changes: 19 additions & 8 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ std::vector<std::string> App::renderTextures(const Glyphs& glyphs, const Config&
return {};

const auto pageNameDigits = getNumberLen(pages.size() - 1);
auto slot = font.face->glyph;

for (std::uint32_t page = 0; page < pages.size(); ++page)
{
Expand All @@ -178,7 +179,7 @@ std::vector<std::string> App::renderTextures(const Glyphs& glyphs, const Config&
const auto y = glyph.y + config.padding.up;

font.renderGlyph(&surface[0], s.w, s.h, x, y,
kv.first, config.color.getBGR());
kv.first, slot->format == FT_GLYPH_FORMAT_SVG ? config.backgroundColor.getBGR() : config.color.getBGR());
}
}

Expand All @@ -187,18 +188,28 @@ std::vector<std::string> App::renderTextures(const Glyphs& glyphs, const Config&
auto cur = surface.data();
const auto end = &surface.back();

const auto fgColor = config.color.getBGR();
const auto bgColor = config.backgroundColor.getBGR();

while (cur <= end)
{
const std::uint32_t a0 = (*cur) >> 24u;
const auto fgColor = (*cur);
const std::uint32_t a0 = fgColor >> 24u;
const std::uint32_t a1 = 256 - a0;
const std::uint32_t rb1 = (a1 * (bgColor & 0xFF00FFu)) >> 8u;
const std::uint32_t rb2 = (a0 * (fgColor & 0xFF00FFu)) >> 8u;
const std::uint32_t g1 = (a1 * (bgColor & 0x00FF00u)) >> 8u;
const std::uint32_t g2 = (a0 * (fgColor & 0x00FF00u)) >> 8u;
*cur = ((rb1 | rb2) & 0xFF00FFu) + ((g1 | g2) & 0x00FF00u);

const std::uint32_t fgB = (fgColor & 0xFF0000u) >> 16u;
const std::uint32_t fgG = (fgColor & 0x00FF00u) >> 8u;
const std::uint32_t fgR = fgColor & 0x0000FFu;

const std::uint32_t bgB = (bgColor & 0xFF0000u) >> 16u;
const std::uint32_t bgG = (bgColor & 0x00FF00u) >> 8u;
const std::uint32_t bgR = bgColor & 0x0000FFu;

const std::uint32_t blB = (a1 * bgB + a0 * fgB) >> 8u;
const std::uint32_t blG = (a1 * bgG + a0 * fgG) >> 8u;
const std::uint32_t blR = (a1 * bgR + a0 * fgR) >> 8u;

*cur = (a0 << 24u) | (blB << 16u) | (blG << 8u) | blR;

++cur;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/external/lunasvg/.github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

custom: ['https://www.paypal.me/sammycage']
31 changes: 31 additions & 0 deletions src/external/lunasvg/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build
on: [push, pull_request]

jobs:
linux:
runs-on: ubuntu-latest
env:
CC: gcc-10
CXX: g++-10
steps:
- uses: actions/checkout@v2
- run: cmake . -DLUNASVG_BUILD_EXAMPLES=ON
- run: make -j 2

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: cmake . -DLUNASVG_BUILD_EXAMPLES=ON
- run: cmake --build .

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- run: cmake . -DLUNASVG_BUILD_EXAMPLES=ON
- run: cmake --build .
- uses: actions/upload-artifact@v2
with:
name: svg2png-windows
path: example\*\svg2png.exe
17 changes: 17 additions & 0 deletions src/external/lunasvg/3rdparty/plutovg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
target_sources(lunasvg
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/plutovg.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-paint.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-geometry.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-blend.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-rle.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-dash.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-ft-raster.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-ft-stroker.c"
"${CMAKE_CURRENT_LIST_DIR}/plutovg-ft-math.c"
)

target_include_directories(lunasvg
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}"
)
166 changes: 166 additions & 0 deletions src/external/lunasvg/3rdparty/plutovg/FTL.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
The FreeType Project LICENSE
----------------------------

2006-Jan-27

Copyright 1996-2002, 2006 by
David Turner, Robert Wilhelm, and Werner Lemberg



Introduction
============

The FreeType Project is distributed in several archive packages;
some of them may contain, in addition to the FreeType font engine,
various tools and contributions which rely on, or relate to, the
FreeType Project.

This license applies to all files found in such packages, and
which do not fall under their own explicit license. The license
affects thus the FreeType font engine, the test programs,
documentation and makefiles, at the very least.

This license was inspired by the BSD, Artistic, and IJG
(Independent JPEG Group) licenses, which all encourage inclusion
and use of free software in commercial and freeware products
alike. As a consequence, its main points are that:

o We don't promise that this software works. However, we will be
interested in any kind of bug reports. (`as is' distribution)

o You can use this software for whatever you want, in parts or
full form, without having to pay us. (`royalty-free' usage)

o You may not pretend that you wrote this software. If you use
it, or only parts of it, in a program, you must acknowledge
somewhere in your documentation that you have used the
FreeType code. (`credits')

We specifically permit and encourage the inclusion of this
software, with or without modifications, in commercial products.
We disclaim all warranties covering The FreeType Project and
assume no liability related to The FreeType Project.


Finally, many people asked us for a preferred form for a
credit/disclaimer to use in compliance with this license. We thus
encourage you to use the following text:

"""
Portions of this software are copyright � <year> The FreeType
Project (www.freetype.org). All rights reserved.
"""

Please replace <year> with the value from the FreeType version you
actually use.


Legal Terms
===========

0. Definitions
--------------

Throughout this license, the terms `package', `FreeType Project',
and `FreeType archive' refer to the set of files originally
distributed by the authors (David Turner, Robert Wilhelm, and
Werner Lemberg) as the `FreeType Project', be they named as alpha,
beta or final release.

`You' refers to the licensee, or person using the project, where
`using' is a generic term including compiling the project's source
code as well as linking it to form a `program' or `executable'.
This program is referred to as `a program using the FreeType
engine'.

This license applies to all files distributed in the original
FreeType Project, including all source code, binaries and
documentation, unless otherwise stated in the file in its
original, unmodified form as distributed in the original archive.
If you are unsure whether or not a particular file is covered by
this license, you must contact us to verify this.

The FreeType Project is copyright (C) 1996-2000 by David Turner,
Robert Wilhelm, and Werner Lemberg. All rights reserved except as
specified below.

1. No Warranty
--------------

THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO
USE, OF THE FREETYPE PROJECT.

2. Redistribution
-----------------

This license grants a worldwide, royalty-free, perpetual and
irrevocable right and license to use, execute, perform, compile,
display, copy, create derivative works of, distribute and
sublicense the FreeType Project (in both source and object code
forms) and derivative works thereof for any purpose; and to
authorize others to exercise some or all of the rights granted
herein, subject to the following conditions:

o Redistribution of source code must retain this license file
(`FTL.TXT') unaltered; any additions, deletions or changes to
the original files must be clearly indicated in accompanying
documentation. The copyright notices of the unaltered,
original files must be preserved in all copies of source
files.

o Redistribution in binary form must provide a disclaimer that
states that the software is based in part of the work of the
FreeType Team, in the distribution documentation. We also
encourage you to put an URL to the FreeType web page in your
documentation, though this isn't mandatory.

These conditions apply to any software derived from or based on
the FreeType Project, not just the unmodified files. If you use
our work, you must acknowledge us. However, no fee need be paid
to us.

3. Advertising
--------------

Neither the FreeType authors and contributors nor you shall use
the name of the other for commercial, advertising, or promotional
purposes without specific prior written permission.

We suggest, but do not require, that you use one or more of the
following phrases to refer to this software in your documentation
or advertising materials: `FreeType Project', `FreeType Engine',
`FreeType library', or `FreeType Distribution'.

As you have not signed this license, you are not required to
accept it. However, as the FreeType Project is copyrighted
material, only this license, or another one contracted with the
authors, grants you the right to use, distribute, and modify it.
Therefore, by using, distributing, or modifying the FreeType
Project, you indicate that you understand and accept all the terms
of this license.

4. Contacts
-----------

There are two mailing lists related to FreeType:

o freetype@nongnu.org

Discusses general use and applications of FreeType, as well as
future and wanted additions to the library and distribution.
If you are looking for support, start in this list if you
haven't found anything to help you in the documentation.

o freetype-devel@nongnu.org

Discusses bugs, as well as engine internals, design issues,
specific licenses, porting, etc.

Our home page can be found at

http://www.freetype.org
Loading