Skip to content

Commit

Permalink
updated res tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Jun 13, 2023
1 parent fc1cbf1 commit cc17bd4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ endif ()

project(ihsplay VERSION ${IHSPLAY_VERSION} LANGUAGES C)

# To suppress warnings for MbedTLS
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif ()
# To suppress warnings for ExternalProject DOWNLOAD_EXTRACT_TIMESTAMP
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif ()

enable_testing()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/core/scripts
${CMAKE_SOURCE_DIR}/third_party/commons/cmake ${CMAKE_SOURCE_DIR}/cmake/sanitizers/cmake)
# Somehow the directory containing FindMbedTLS.cmake must be in the first place
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/core/scripts ${CMAKE_SOURCE_DIR}/third_party/commons/cmake
${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/cmake/sanitizers/cmake)

# Use `pkg-config` to link needed libraries.
find_package(PkgConfig REQUIRED)
find_package(Freetype REQUIRED)
find_package(Fontconfig REQUIRED)
find_package(MbedTLS)
find_package(MbedTLS REQUIRED)

# Use SDL2 for window creation and event handling.
pkg_check_modules(SDL2 REQUIRED sdl2)
Expand Down
2 changes: 1 addition & 1 deletion third_party/commons
18 changes: 4 additions & 14 deletions tools/resource-tools/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {dest, parallel, src} from "gulp";
import binheader from "./binheader";
import codepoints from "./codepoints";
import asyncTransform from "./async-transform";
import rename from "gulp-rename";
import subsetFont from "./gulp-subset-font";
import symheader from "./symheader";

const outDir = '../../app/lvgl/fonts/bootstrap-icons';

Expand All @@ -25,19 +25,9 @@ async function iconfont() {
async function symlist() {
return src('res/bootstrap-icons.woff2')
.pipe(codepoints())
.pipe(asyncTransform(async file => {
const codepoints: Record<string, number> = codepointsMetadata(file);
let content = '#pragma once\n\n';
const encoder = new TextEncoder();
for (let key in codepoints) {
const cp: number = codepoints[key];
const value = Array.from(encoder.encode(String.fromCodePoint(cp)))
.map(v => `\\x${v.toString(16)}`).join('');
const name = key.toUpperCase().replace(/[^0-9a-z_]/ig, '_');
content += `#define BS_SYMBOL_${name} "${value}"\n`;
}
file.contents = Buffer.from(content);
file.basename = 'symbols.h';
.pipe(symheader({prefix: 'BS'}))
.pipe(rename(file => {
file.basename = 'symbols';
}))
.pipe(dest(outDir));
}
Expand Down
26 changes: 26 additions & 0 deletions tools/resource-tools/symheader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import asyncTransform from "./async-transform";

export interface Option {
prefix: string;
}

function codepointsMetadata(file: any): Record<string, number> {
return file.codepoints;
}

export default function symheader(option?: Partial<Option>) {
return asyncTransform(async file => {
const codepoints: Record<string, number> = codepointsMetadata(file);
let content = '#pragma once\n\n';
const encoder = new TextEncoder();
for (let key in codepoints) {
const cp: number = codepoints[key];
const value = Array.from(encoder.encode(String.fromCodePoint(cp)))
.map(v => `\\x${v.toString(16)}`).join('');
const name = key.toUpperCase().replace(/[^0-9a-z_]/ig, '_');
content += `#define ${option.prefix}_SYMBOL_${name} "${value}"\n`;
}
file.contents = Buffer.from(content);
file.extname = '.h';
})
}

0 comments on commit cc17bd4

Please sign in to comment.