Skip to content

Commit

Permalink
Make it easier to change the bundled font.
Browse files Browse the repository at this point in the history
This makes it easier to play CJK games, since the embedded font must have
the glyphs necessary to display the game text.

The qmake portion is untested, but should hopefully not break the build.

See also Ancurio#135
  • Loading branch information
mook committed Oct 26, 2015
1 parent 7bf6eca commit 8d5c841
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ option(WORKDIR_CURRENT "Keep current directory on startup" OFF)
option(FORCE32 "Force 32bit compile on 64bit OS" OFF)
set(BINDING "MRI" CACHE STRING "The Binding Type (MRI, MRUBY, NULL)")
set(EXTERNAL_LIB_PATH "" CACHE PATH "External precompiled lib prefix")
set(BUNDLED_FONT "liberation" CACHE STRING "Bundled font name; file must exist in assets")
set_property(CACHE BUNDLED_FONT PROPERTY ADVANCED ON)

## Misc setup ##

Expand Down Expand Up @@ -234,7 +236,7 @@ set(EMBEDDED_INPUT
shader/blurH.vert
shader/blurV.vert
shader/simpleMatrix.vert
assets/liberation.ttf
assets/${BUNDLED_FONT}.ttf

This comment has been minimized.

Copy link
@Ancurio

Ancurio Oct 29, 2015

I don't feel very strongly about hardcoding the assets/ part, but forcing a .ttf extension feels wrong, since that is not the only type supported by SDL_ttf (and more types might be supported in the future).

assets/icon.png
)

Expand Down Expand Up @@ -402,6 +404,7 @@ add_executable(${PROJECT_NAME} MACOSX_BUNDLE

target_compile_definitions(${PROJECT_NAME} PRIVATE
${DEFINES}
BUNDLED_FONT=${BUNDLED_FONT}
)
target_include_directories(${PROJECT_NAME} PRIVATE
src
Expand Down
2 changes: 2 additions & 0 deletions mkxp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ defineReplace(xxdOutput) {
return($$basename(1).xxd)
}

DEFINES += BUNDLED_FONT=liberation

# xxd
xxd.output_function = xxdOutput
xxd.commands = xxd -i ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT}
Expand Down
5 changes: 4 additions & 1 deletion src/bundledfont.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#include "liberation.ttf.xxd"
#define BUNDLED_FONT_NAME BUNDLED_FONT.ttf.xxd
#define STRINGIFY(x) #x
#define INCLUDE_FILE(x) STRINGIFY(x)
#include INCLUDE_FILE(BUNDLED_FONT_NAME)
12 changes: 5 additions & 7 deletions src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@

#include <SDL_ttf.h>

#define BUNDLED_FONT liberation
#define BUNDLED_FONT_D(f) assets_## f ##_ttf
#define BUNDLED_FONT_L(f) assets_## f ##_ttf_len

#define BUNDLED_FONT_DECL(FONT) \
extern unsigned char assets_##FONT##_ttf[]; \
extern unsigned int assets_##FONT##_ttf_len;

BUNDLED_FONT_DECL(liberation)
extern unsigned char BUNDLED_FONT_D(FONT)[]; \
extern unsigned int BUNDLED_FONT_L(FONT);

#define BUNDLED_FONT_D(f) assets_## f ##_ttf
#define BUNDLED_FONT_L(f) assets_## f ##_ttf_len
BUNDLED_FONT_DECL(BUNDLED_FONT)

// Go fuck yourself CPP
#define BNDL_F_D(f) BUNDLED_FONT_D(f)
Expand Down

0 comments on commit 8d5c841

Please sign in to comment.