Commit Graph

7 Commits (fbc5bfc27f7e7ba860c1e62a66af07fc16c0a07e)

Author SHA1 Message Date
whitequark fc79642788 Move vector font to res/fonts/; remove lff2c.
This commit integrates the vector font in the resource system, so
that cross-compilation would be easier and a custom font could be
used without recompilation.

The font handling code was carefully written to lazily load glyphs;
as possible; in practice this means that startup is less than 15ms
slower after this commit, most of it spent in inflate().

This also reduces executable size and makes compilation of
glhelper.cpp much faster.
2016-05-18 11:24:24 +00:00
whitequark 645c2d90ac Move bitmap font to res/fonts/; remove unifont2c.
This commit integrates the bitmap font in the resource system, so
that cross-compilation would be easier.

The font handling code was carefully written to do glyph parsing
lazily; in practice this means that after this commit, startup
is less than 25ms slower, most of it spent in inflate().

This should also result in faster rendering, since there is no
rampant plane switching anymore; instead, all characters that are
actually used are stashed into same one texture.
2016-05-18 11:24:24 +00:00
whitequark a525f03371 Move icons to res/icons/; remove png2c.
This commit integrates icons in the resource system so that they
can be loaded (or reloaded, without restarting) in @2x mode, which
will be added in a future commit. png2c is no longer necessary.

png2c used to perform the following transformation:
  if(r + g + b < 11) r = g = b = 11;

This is now achieved by switching the icons to RGBA mode and adding
alpha channel with the following imagemagick invocation, which is
equivalent to the transformation above:
  for i in *.png; do
    convert -fuzz 4% -channel rgba -matte \
            -fill "rgba(255,255,255,0)" -opaque black \
            $i $i
  done

The Debian package solvespace now includes /usr/share/solvespace;
this should be split out into solvespace-data later.
2016-05-18 11:24:24 +00:00
whitequark 4c01461316 OS X: move resources to res/. 2016-05-18 11:24:23 +00:00
whitequark e36ee32def freedesktop: move resources to res/. 2016-05-18 11:24:23 +00:00
whitequark a6b6d98a94 Win32: move resources to res/. 2016-05-18 11:24:23 +00:00
whitequark f4c01f670c Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:

  * Cross-compilation is complicated. Right now, it is necessary
    to be able to run executables for the target platform; this
    happens to work with wine-binfmt installed, but is rather ugly.

  * Icons can only have one resolution. On OS X, modern software is
    expected to take advantage of high-DPI ("Retina") screens and
    use so-called @2x assets when ran in high-DPI mode.

  * Localization is complicated. Win32 and OS X provide built-in
    support for loading the resource appropriate for the user's
    locale.

  * Embedding strings can only be done as raw strings, using C++'s
    R"(...)" literals. This precludes embedding sizable strings,
    e.g. JavaScript libraries as used in Three.js export, and makes
    git history less useful. Not embedding the libraries means we
    have to rely on external CDNs, which requires an Internet
    connection and adds a glaring point of failure.

  * Linux distribution guidelines are violated. All architecture-
    independent data, especially large data such as fonts, is
    expected to be in /usr/share, not in the binary.

  * Customization is impossible without recompilation. Minor
    modifications like adding a few missing vector font characters
    or adjusting localization require a complete development
    environment, which is unreasonable to expect from users of
    a mechanical CAD.

As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:

  * on Win32: into resources of the executable, which allows us to
    keep distributing one file;
  * on OS X: into the app bundle;
  * on other *nix: into /usr/share/solvespace/ or ../res/ (relative
    to the executable path), the latter allowing us to run freshly
    built executables without installation.

It also subsides the platform-specific resources that are in src/.

The resource system is not yet used for anything; this will be added
in later commits.
2016-05-18 11:24:23 +00:00