### Create slughorn static library target Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt Creates the static library target 'slughorn' from slughorn/slughorn.cpp, sets public include directories for build and install interfaces, requires C++20, applies private compile options, and enables position-independent code. ```cmake add_library(slughorn STATIC "slughorn/slughorn.cpp") target_include_directories(slughorn PUBLIC # When used as a submodule, consumers get our headers via this path $ $ ) target_compile_features(slughorn PUBLIC cxx_std_20) target_compile_options(slughorn PRIVATE ${SLUGHORN_COMPILE_OPTIONS}) set_target_properties(slughorn PROPERTIES POSITION_INDEPENDENT_CODE ON) ``` -------------------------------- ### DOM element references and state variables Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Gets references to all interactive elements and initializes state variables for emoji list, font, and canvas panning. ```javascript const fontSelect = document.getElementById("fontSelect"); const emojiList = document.getElementById("emojiList"); const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); const statusEl = document.getElementById("status"); const hud = document.getElementById("hud"); const sizeRange = document.getElementById("sizeRange"); const sizeLabel = document.getElementById("sizeLabel"); const search = document.getElementById("search"); const customCp = document.getElementById("customCp"); const customGo = document.getElementById("customGo"); const reloadEmoji = document.getElementById("reloadEmoji"); const fitButton = document.getElementById("fit"); const stageWrap = document.getElementById("stageWrap"); let emojis = []; let filtered = []; let selected = null; let currentFontFace = null; let currentFontFamily = "SlughornEmojiTest"; let fontSourceLabel = ""; let panX = 0; let panY = 0; let dragging = false; let dragStart = null; ``` -------------------------------- ### CMakeLists.txt for slughorn-example-glfw target Source: https://github.com/alphapixel/slughorn/blob/main/example/CMakeLists.txt Complete CMake configuration for the slughorn-example-glfw executable. Requires SLUGHORN_FREETYPE to be ON, otherwise it skips with a warning. Fetches GLAD and GLFW via FetchContent, sets GLFW build options to disable docs/tests/examples, and links against the slughorn core library. Assumes slughorn is already a CMake target; adjust if building standalone. ```cmake if(NOT SLUGHORN_FREETYPE) message(WARNING "SLUGHORN_BUILD_EXAMPLES=ON but SLUGHORN_FREETYPE=OFF; slughorn-example-glfw requires FreeType (it loads glyphs via slughorn::freetype::loadFontGlyphs), skipping") return() endif() include(FetchContent) # ---------------------------------------------------------------------------- # GLAD (GL 3.3 core, no extensions needed) # # We use the davidcralph/glad-cmake wrapper which fetches from the official # GLAD2 generator output. If you already have a glad/ directory vendored in # your repo, skip this block and just add_subdirectory(glad) instead. # ---------------------------------------------------------------------------- FetchContent_Declare( glad GIT_REPOSITORY https://github.com/Dav1dde/glad.git GIT_TAG v0.1.36 # last stable v1 release; use v2 branch for GLAD2 GIT_SHALLOW TRUE ) FetchContent_MakeAvailable(glad) # ---------------------------------------------------------------------------- # GLFW 3.x # # BUILD_SHARED_LIBS=OFF keeps it static (no .dll/.so to ship alongside the demo). # The GLFW_* options silence docs/tests/examples that we don't need. # ---------------------------------------------------------------------------- FetchContent_Declare( glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.4 GIT_SHALLOW TRUE ) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(glfw) # ---------------------------------------------------------------------------- # slughorn-example-glfw # ---------------------------------------------------------------------------- add_executable(slughorn-example-glfw "slughorn-example-glfw.cpp" # If slughorn is not already a library target in your build, add here: # ${CMAKE_SOURCE_DIR}/slughorn.cpp ) target_link_libraries(slughorn-example-glfw PRIVATE slughorn # your existing core library target glad glfw ) # slughorn-canvas.hpp is header-only; just needs to be on the include path. # Adjust if your layout differs. target_include_directories(slughorn-example-glfw PRIVATE ${CMAKE_SOURCE_DIR} # for slughorn.hpp, slughorn-canvas.hpp ) # GL 3.3 core; tell GLAD what to generate (only needed for the GLAD v1 cmake target) target_compile_definitions(slughorn-example-glfw PRIVATE GLAD_GLAPI_EXPORT ) set_target_properties(slughorn-example-glfw PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) ``` -------------------------------- ### Compile Skia with GN and Ninja Source: https://github.com/alphapixel/slughorn/blob/main/README.md Builds the Skia library from source. Run these commands in order from the Skia source directory. The commands remove the previous Release output, generate the build files, and compile the skia target. ```bash cd ~/dev/skia rm -rf out/Release bin/gn gen out/Release ninja -C out/Release skia ``` -------------------------------- ### Enable SLUGHORN_NANOSVG with patches Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt Conditionally enables NanoSVG support when SLUGHORN_NANOSVG is set. Requires the ext/nanosvg submodule and Git. Applies three patch files to fix upstream issues (gradient units, id inheritance, OBB linear gradient coordinates) using git apply with --reverse --check to avoid double-applying, and --ignore-whitespace to handle CRLF checkouts. Defines SLUGHORN_NANOSVG_IMPLEMENTATION privately and SLUGHORN_HAS_NANOSVG publicly, and adds the nanosvg src directory as a system include. ```cmake if(SLUGHORN_NANOSVG) if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg") message(FATAL_ERROR "ext/nanosvg not found. Run:\n" " git submodule update --init --recursive" ) endif() find_package(Git REQUIRED) # NanoSVG upstream is missing a few fixes we depend on (NSVGgradient::units, # nsvg__pushAttr id inheritance, OBB linear gradient coordinate handling). # Apply them here so a fresh submodule checkout builds without manual steps. # --reverse --check detects an already-patched tree so reconfiguring never # double-applies or errors out. set(SLUGHORN_NANOSVG_PATCHES "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg-00-gradient-units-field.diff" "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg-01-push-attr-id-inherit.diff" "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg-02-obb-linear-gradient-coords.diff" ) # --ignore-whitespace guards against CRLF-checked-out submodules (e.g. Windows # with core.autocrlf=true) not matching these LF patch files context-for-context. foreach(_slughorn_nanosvg_patch ${SLUGHORN_NANOSVG_PATCHES}) execute_process( COMMAND "${GIT_EXECUTABLE}" apply --reverse --check --ignore-whitespace "${_slughorn_nanosvg_patch}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg" RESULT_VARIABLE _slughorn_nanosvg_patch_applied OUTPUT_QUIET ERROR_QUIET ) if(NOT _slughorn_nanosvg_patch_applied EQUAL 0) message(STATUS "Applying nanosvg patch: ${_slughorn_nanosvg_patch}") execute_process( COMMAND "${GIT_EXECUTABLE}" apply --ignore-whitespace "${_slughorn_nanosvg_patch}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg" RESULT_VARIABLE _slughorn_nanosvg_patch_result ) if(NOT _slughorn_nanosvg_patch_result EQUAL 0) message(FATAL_ERROR "Failed to apply nanosvg patch: ${_slughorn_nanosvg_patch}") endif() endif() endforeach() target_compile_definitions(slughorn PRIVATE SLUGHORN_NANOSVG_IMPLEMENTATION) target_compile_definitions(slughorn PUBLIC SLUGHORN_HAS_NANOSVG) target_include_directories(slughorn SYSTEM PUBLIC $ ) endif() ``` -------------------------------- ### Enable SLUGHORN_SERIAL with nlohmann_json Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt Conditionally enables serialization support when SLUGHORN_SERIAL is set. Requires the ext/json submodule; fails with a fatal error if missing. Adds the json subdirectory, defines SLUGHORN_SERIAL_IMPLEMENTATION privately and SLUGHORN_HAS_SERIAL publicly, and links nlohmann_json privately. ```cmake if(SLUGHORN_SERIAL) if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ext/json") message(FATAL_ERROR "ext/json not found. Run:\n" " git submodule update --init --recursive" ) endif() add_subdirectory("ext/json") target_compile_definitions(slughorn PRIVATE SLUGHORN_SERIAL_IMPLEMENTATION) target_compile_definitions(slughorn PUBLIC SLUGHORN_HAS_SERIAL) target_link_libraries(slughorn PRIVATE nlohmann_json::nlohmann_json) endif() ``` -------------------------------- ### Populate font selector Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Fills the font select dropdown with options from FONT_FILES. ```javascript function populateFonts() { fontSelect.innerHTML = ""; for(const path of FONT_FILES) { const option = document.createElement("option"); option.value = path; option.textContent = path; fontSelect.appendChild(option); } } ``` -------------------------------- ### Custom codepoint navigation Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Jumps to an arbitrary codepoint, adding it to the browsable list if not present, and renders the list. ```javascript // Jumps to an arbitrary codepoint even if it's not in emoji.hpp's name table (e.g. the legacy // PUA codepoints some COLRv1 fonts use for flags/blend-mode test glyphs). Adds it to the browsable // list (once) rather than only rendering it ad hoc, so it stays selectable/searchable afterward. function goToCustomCodepoint() { const cp = parseCodepointInput(customCp.value); if(cp === null) { setStatus(`Invalid codepoint: "${customCp.value}" (try 0x1F600 or U+1F600)`); return; } const existing = emojis.find(([, c]) => c === cp); const entry = existing || [`custom ${cpToHex(cp)}`, cp]; if(!existing) emojis = [entry, ...emojis]; selected = entry; search.value = ""; renderList(); } ``` -------------------------------- ### Load emoji table with fallback Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Attempts to fetch emoji.hpp from candidate paths, falling back to built-in emojis if fetch fails. ```javascript async function loadEmojiTable() { const candidates = [ "emoji.hpp", // "slughorn/emoji.hpp", // "include/slughorn/emoji.hpp", // "../include/slughorn/emoji.hpp", ]; for(const url of candidates) { try { const response = await fetch(url, { cache: "no-cache" }); if(!response.ok) continue; const text = await response.text(); const parsed = parseEmojiHpp(text); if(parsed.length > 0) { emojis = parsed; setStatus(`Loaded ${parsed.length} emojis from ${url}`); return; } } catch(err) { // file:// and CORS failures land here. That's fine. } } emojis = FALLBACK_EMOJIS.slice(); setStatus( `Could not fetch slughorn/emoji.hpp; using ${emojis.length} built-in fallback emojis. ` + `Run from repo root with: python3 -m http.server` ); } ``` -------------------------------- ### Font and fallback emoji configuration Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Defines the list of font files to test and a fallback emoji table used when emoji.hpp cannot be fetched. ```javascript const FONT_FILES = [ "font/COLRv0/EmojiTwoCOLRv0.ttf", "font/COLRv0/TwemojiCOLRv0.ttf", "font/COLRv0/OpenMojiCOLRv0.ttf", "font/COLRv0/segoe-ui-emoji_0.ttf", "font/COLRv0/Twemoji.Mozilla.ttf", "font/COLRv1/twemoji-glyf_colr_1.ttf", "font/COLRv1/noto-glyf_colr_1.ttf", "font/COLRv1/NotoColorEmoji-Regular.ttf", ]; const FALLBACK_EMOJIS = [ ["dragon", 0x1F409], ["dragon_face", 0x1F432], ["puzzle_piece", 0x1F9E9], ["rocket", 0x1F680], ["alien", 0x1F47D], ["robot", 0x1F916], ["ghost", 0x1F47B], ["fire", 0x1F525], ["t_rex", 0x1F996], ["guitar", 0x1F3B8], ["satellite", 0x1F6F0], ["flying_saucer", 0x1F6F8], ["skull", 0x1F480], ["heart_suit", 0x02665], ["red_heart", 0x02764], ["cat_face", 0x1F431], ["dog_face", 0x1F436], ["frog", 0x1F438], ["unicorn", 0x1F984], ["zombie", 0x1F9DF], ]; ``` -------------------------------- ### Add earcut tessellation include with SLUGHORN_TESSELLATE Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt When SLUGHORN_TESSELLATE is enabled, requires ext/earcut submodule and adds its include directory. Defines SLUGHORN_HAS_TESSELLATE. ```cmake if(SLUGHORN_TESSELLATE) if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ext/earcut") message(FATAL_ERROR "ext/earcut not found. Run:\n" " git submodule update --init --recursive" ) endif() target_compile_definitions(slughorn PUBLIC SLUGHORN_HAS_TESSELLATE) target_include_directories(slughorn SYSTEM PUBLIC $ ) endif() ``` -------------------------------- ### Enable msdfgen SDF dependency with MSDFGEN_* cache variables Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt When SLUGHORN_SDF is enabled, requires the ext/msdfgen submodule, forces msdfgen build options, and links msdfgen-core. Overrides MSDFGEN_DYNAMIC_RUNTIME on MSVC to match the project's dynamic CRT linkage. ```cmake if(SLUGHORN_SDF) if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ext/msdfgen") message(FATAL_ERROR "ext/msdfgen not found. Run:\n" " git submodule update --init --recursive" ) endif() set(MSDFGEN_CORE_ONLY ON CACHE BOOL "" FORCE) set(MSDFGEN_BUILD_STANDALONE OFF CACHE BOOL "" FORCE) set(MSDFGEN_USE_VCPKG OFF CACHE BOOL "" FORCE) set(MSDFGEN_USE_OPENMP ${SLUGHORN_RENDER_PARALLEL} CACHE BOOL "" FORCE) set(MSDFGEN_USE_SKIA OFF CACHE BOOL "" FORCE) set(MSDFGEN_DISABLE_SVG OFF CACHE BOOL "" FORCE) set(MSDFGEN_DISABLE_PNG OFF CACHE BOOL "" FORCE) # The rest of the project (and the vcpkg triplet's VCPKG_CRT_LINKAGE) links # the dynamic CRT; msdfgen's own default of static breaks the MSVC link # with a RuntimeLibrary mismatch (MDd vs MTd). This property is a no-op # outside MSVC, so only override it there. if(MSVC) set(MSDFGEN_DYNAMIC_RUNTIME ON CACHE BOOL "" FORCE) else() set(MSDFGEN_DYNAMIC_RUNTIME OFF CACHE BOOL "" FORCE) endif() set(MSDFGEN_INSTALL OFF CACHE BOOL "" FORCE) add_subdirectory("ext/msdfgen") set_target_properties(msdfgen-core PROPERTIES POSITION_INDEPENDENT_CODE ON) target_compile_definitions(slughorn PUBLIC SLUGHORN_HAS_SDF) target_include_directories(slughorn SYSTEM PUBLIC $ ) target_link_libraries(slughorn PUBLIC msdfgen-core) endif() ``` -------------------------------- ### Configure optional slughorn tests with CTest Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt Optional test suite enabled with -DSLUGHORN_BUILD_TESTS=ON. Builds and registers CTest targets for Cairo, Blend2D, NanoSVG, Tessellate, canvas, and render backends, each guarded by its corresponding SLUGHORN_* option. Also defines convenience targets canvas-list and canvas-info that regenerate canvas.slug and invoke the slughorn CLI. ```cmake option(SLUGHORN_BUILD_TESTS "Compile testing files" OFF) if(SLUGHORN_BUILD_TESTS) enable_testing() find_package(PkgConfig REQUIRED) # Cairo (optional) pkg_check_modules(CAIRO IMPORTED_TARGET cairo) if(CAIRO_FOUND) add_executable(slughorn-test-cairo "test/slughorn-test-cairo.cpp") target_link_libraries(slughorn-test-cairo PRIVATE slughorn PkgConfig::CAIRO) add_test(NAME cairo COMMAND slughorn-test-cairo) message(STATUS "slughorn tests: Cairo found, building slughorn-test-cairo") else() message(STATUS "slughorn tests: Cairo not found, skipping slughorn-test-cairo") endif() # Blend2D (optional - requires SLUGHORN_BLEND2D=ON) if(SLUGHORN_BLEND2D) add_executable(slughorn-test-blend2d "test/slughorn-test-blend2d.cpp") target_link_libraries(slughorn-test-blend2d PRIVATE slughorn) add_test(NAME blend2d COMMAND slughorn-test-blend2d) message(STATUS "slughorn tests: Blend2D enabled, building slughorn-test-blend2d") else() message(STATUS "slughorn tests: SLUGHORN_BLEND2D=OFF, skipping slughorn-test-blend2d") endif() # NanoSVG (optional - requires SLUGHORN_NANOSVG=ON) if(SLUGHORN_NANOSVG) add_executable(slughorn-test-nanosvg "test/slughorn-test-nanosvg.cpp") target_include_directories(slughorn-test-nanosvg PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg/src" ) target_link_libraries(slughorn-test-nanosvg PRIVATE slughorn) add_test(NAME nanosvg COMMAND slughorn-test-nanosvg) message(STATUS "slughorn tests: NanoSVG enabled, building slughorn-test-nanosvg") else() message(STATUS "slughorn tests: SLUGHORN_NANOSVG=OFF, skipping slughorn-test-nanosvg") endif() # Tessellate (optional - requires SLUGHORN_TESSELLATE=ON) if(SLUGHORN_TESSELLATE) add_executable(slughorn-test-tessellate "test/slughorn-test-tessellate.cpp") target_link_libraries(slughorn-test-tessellate PRIVATE slughorn) add_test(NAME tessellate COMMAND slughorn-test-tessellate) message(STATUS "slughorn tests: Tessellate enabled, building slughorn-test-tessellate") else() message(STATUS "slughorn tests: SLUGHORN_TESSELLATE=OFF, skipping slughorn-test-tessellate") endif() if(SLUGHORN_SERIAL) add_executable(slughorn-test-canvas "test/slughorn-test-canvas.cpp") target_link_libraries(slughorn-test-canvas PRIVATE slughorn) add_test(NAME canvas COMMAND slughorn-test-canvas) message(STATUS "slughorn tests: serial found, building slughorn-test-canvas") # Convenience targets: regenerate canvas.slug when the binary changes, # then inspect it via the CLI without needing to type paths manually. # # make canvas-list - list all shape + composite keys # make canvas-info - atlas summary (dimensions, packing stats) set(_CANVAS_SLUG "${CMAKE_CURRENT_BINARY_DIR}/canvas.slug") add_custom_command( OUTPUT ${_CANVAS_SLUG} COMMAND $ ${_CANVAS_SLUG} DEPENDS slughorn-test-canvas COMMENT "Generating canvas.slug" ) add_custom_target(canvas-list COMMAND ${CMAKE_SOURCE_DIR}/bin/slughorn list ${_CANVAS_SLUG} DEPENDS ${_CANVAS_SLUG} USES_TERMINAL ) add_custom_target(canvas-info COMMAND ${CMAKE_SOURCE_DIR}/bin/slughorn info ${_CANVAS_SLUG} DEPENDS ${_CANVAS_SLUG} USES_TERMINAL ) add_executable(slughorn-test-render "test/slughorn-test-render.cpp") target_link_libraries(slughorn-test-render PRIVATE slughorn) add_test(NAME render COMMAND slughorn-test-render) message(STATUS "slughorn tests: building slughorn-test-render") else() message(STATUS "slughorn tests: SLUGHORN_SERIAL=OFF, skipping slughorn-test-canvas and slughorn-test-render") endif() # if(SLUGHORN_GLFW) # find_package(glfw3 REQUIRED) # add_executable(slughorn-test-glfw "test/slughorn-test-glfw.cpp") # target_link_libraries(slughorn-test-glfw PRIVATE slughorn glfw glad) # message(STATUS "slughorn tests: GLFW found, building slughorn-test-glfw") # else() # message(STATUS "slughorn tests: SLUGHORN_GLFW=OFF, skipping slughorn-test-glfw") # endif() # add_executable(slughorn-test-mvt "test/slughorn-test-mvt.cpp") # target_link_libraries(slughorn-test-mvt PRIVATE slughorn) # target_compile_options(slughorn-test-mvt PRIVATE ${SLUGHORN_COMPILE_OPTIONS}) # target_include_directories(slughorn-test-mvt PRIVATE # "${CMAKE_CURRENT_SOURCE_DIR}/../protozero/include" # "${CMAKE_CURRENT_SOURCE_DIR}/../vtzero/include" # ) endif() ``` -------------------------------- ### Link blend2d with SLUGHORN_BLEND2D Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt Locates blend2d with find_package, requires it, and links slughorn to blend2d::blend2d. Defines SLUGHORN_HAS_BLEND2D. ```cmake if(SLUGHORN_BLEND2D) find_package(blend2d REQUIRED) target_compile_definitions(slughorn PUBLIC SLUGHORN_HAS_BLEND2D) target_link_libraries(slughorn PUBLIC blend2d::blend2d) endif() ``` -------------------------------- ### Codepoint conversion and parsing helpers Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Functions to convert codepoints to hex strings, to characters, and to parse user input accepting 0x, U+, or bare hex. ```javascript function cpToHex(cp) { return "U+" + cp.toString(16).toUpperCase().padStart(4, "0"); } function cpToString(cp) { return String.fromCodePoint(cp); } // Accepts "0x1F600", "U+1F600", or a bare "1F600" - always parsed as hex. function parseCodepointInput(text) { const match = text.trim().match(/^(?:0x|U\+)?([0-9A-Fa-f]+)$/i); if(!match) return null; const cp = parseInt(match[1], 16); if(!Number.isFinite(cp) || cp < 0 || cp > 0x10FFFF) return null; return cp; } ``` -------------------------------- ### JavaScript functions for emoji font loading and rendering Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html These functions handle loading fonts (preset or dropped), searching and rendering the emoji list, resizing the canvas for device pixel ratio, and drawing the selected emoji with HUD overlays. ```JavaScript async function loadSelectedFont() { if(!currentFontFace) { document.documentElement.style.setProperty("--emoji-font", "system-ui, sans-serif"); currentFontFamily = "system-ui, sans-serif"; } const faceName = fontSelect.value; try { const newFace = new FontFace("SlughornEmojiSelected", `url("${faceName}")`); await newFace.load(); document.fonts.add(newFace); document.fonts.delete(currentFontFace); currentFontFace = newFace; currentFontFamily = "SlughornEmojiSelected"; document.documentElement.style.setProperty("--emoji-font", `"${currentFontFamily}"`); } catch(err) { setStatus(`Loaded face failed: ${faceName} — ${err.message}`); } renderList(); draw(); } async function loadDroppedFont(file) { if(!file) return; const url = URL.createObjectURL(file); fontSourceLabel = file.name; try { if(currentFontFace) { document.fonts.delete(currentFontFace); currentFontFace = null; } const family = "SlughornEmojiDropped"; const face = new FontFace(family, `url("${url}")`); await face.load(); document.fonts.add(face); currentFontFace = face; currentFontFamily = family; document.documentElement.style.setProperty("--emoji-font", `"${family}"`); setStatus(`Loaded dropped font: ${file.name}`); } catch(err) { setStatus(`Dropped font load failed: ${file.name} — ${err.message}`); } renderList(); draw(); } function renderList() { const q = search.value.trim().toLowerCase(); filtered = emojis.filter(([name, cp]) => { if(!q) return true; return name.includes(q) || cpToHex(cp).toLowerCase().includes(q); }); emojiList.innerHTML = ""; for(const [name, cp] of filtered) { const button = document.createElement("button"); button.className = "emojiButton"; if(selected && selected[0] === name) button.classList.add("selected"); const glyph = document.createElement("div"); glyph.className = "emojiGlyph"; glyph.textContent = cpToString(cp); const meta = document.createElement("div"); meta.className = "emojiMeta"; const nameEl = document.createElement("div"); nameEl.className = "emojiName"; nameEl.textContent = name; const codeEl = document.createElement("div"); codeEl.className = "emojiCode"; codeEl.textContent = cpToHex(cp); meta.append(nameEl, codeEl); button.append(glyph, meta); button.addEventListener("click", () => { selected = [name, cp]; renderList(); draw(); }); emojiList.appendChild(button); } if(!selected && filtered.length > 0) selected = filtered[0]; draw(); } function resizeCanvas() { const dpr = window.devicePixelRatio || 1; const rect = canvas.getBoundingClientRect(); const w = Math.max(1, Math.floor(rect.width * dpr)); const h = Math.max(1, Math.floor(rect.height * dpr)); if(canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; } draw(); } function draw() { if(!ctx) return; const dpr = window.devicePixelRatio || 1; const w = canvas.width; const h = canvas.height; const cssW = w / dpr; const cssH = h / dpr; const fontSize = Number(sizeRange.value); ctx.save(); ctx.setTransform(dpr, 0, 0, dpr, 0, 0); ctx.clearRect(0, 0, cssW, cssH); ctx.fillStyle = "rgba(0, 0, 0, 0.28)"; ctx.fillRect(0, 0, cssW, cssH); ctx.strokeStyle = "rgba(255, 255, 255, 0.12)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(cssW / 2 + panX, 0); ctx.lineTo(cssW / 2 + panX, cssH); ctx.moveTo(0, cssH / 2 + panY); ctx.lineTo(cssW, cssH / 2 + panY); ctx.stroke(); if(selected) { const [name, cp] = selected; const glyph = cpToString(cp); ctx.font = `${fontSize}px "${currentFontFamily}", system-ui, sans-serif`; ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.fillStyle = "white"; ctx.fillText(glyph, cssW / 2 + panX, cssH / 2 + panY); hud.textContent = `${name}\n` + `${cpToHex(cp)} ${glyph}\n` + `font: ${fontSourceLabel || "(system fallback)"}\n` + `size: ${fontSize}px dpr: ${dpr.toFixed(2)}\n` + `wheel: zoom drag: pan`; } else { ctx.fillStyle = "#d8dde8"; ctx.font = "20px system-ui, sans-serif"; ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.fillText("No emoji selected", cssW / 2, cssH / 2); hud.textContent = ""; } ctx.restore(); sizeLabel.textContent = `${fontSize}px`; } function fitSelected() { const rect = canvas.getBoundingClientRect(); const s = Math.floor(Math.min(rect.width, rect.height) * 0.58); sizeRange.value = String(Math.max(16, Math.min(512, s))); panX = 0; panY = 0; draw(); } function initInput() { fontSelect.addEventListener("change", loadSelectedFont); sizeRange.addEventListener("input", draw); search.addEventListener("input", () => { renderList(); }); customGo.addEventListener("click", goToCustomCodepoint); customCp.addEventListener("keydown", event => { if(event.key === "Enter") goToCustomCodepoint(); }); reloadEmoji.addEventListener("click", async () => { selected = null; await loadEmojiTable(); renderList(); }); fitButton.addEventListener("click", fitSelected); canvas.addEventListener("wheel", event => { event.preventDefault(); const oldSize = Number(sizeRange.value); const factor = event.deltaY < 0 ? 1.08 : 1 / 1.08; const next = Math.max(16, Math.min(512, Math.round(oldSize * factor))); sizeRange.value = String(next); draw(); }, { passive: false }); canvas.addEventListener("pointerdown", event => { dragging = true; canvas.setPointerCapture(event.pointerId); dragStart = { x: event.clientX, y: event.clientY, panX, panY, }; }); canvas.addEventListener("pointermove", event => { if(!dragging || !dragStart) return; panX = dragStart.panX + (event.clientX - dragStart.x); panY = dragStart.panY + (event.clientY - dragStart.y); draw(); }); canvas.addEventListener("pointerup", event => { dragging = false; dragStart = null; canvas.releasePointerCapture(event.pointerId); }); } ``` -------------------------------- ### Enable SLUGHORN_FREETYPE with Freetype Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt Conditionally enables FreeType support when SLUGHORN_FREETYPE is set. Requires the Freetype package, defines SLUGHORN_FREETYPE_IMPLEMENTATION privately and SLUGHORN_HAS_FREETYPE publicly, and links Freetype::Freetype publicly. Includes commented-out code for a submodule check and include directories. ```cmake if(SLUGHORN_FREETYPE) # if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanosvg") # message(FATAL_ERROR # "ext/nanosvg not found. Run:\n" # " git submodule update --init --recursive" # ) # endif() find_package(Freetype REQUIRED) target_compile_definitions(slughorn PRIVATE SLUGHORN_FREETYPE_IMPLEMENTATION) target_compile_definitions(slughorn PUBLIC SLUGHORN_HAS_FREETYPE) # target_include_directories(slughorn # PUBLIC # $ # $ # $ # ) target_link_libraries(slughorn PUBLIC Freetype::Freetype) endif() ``` -------------------------------- ### Enable OpenMP parallel rendering with SLUGHORN_RENDER_PARALLEL Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt When SLUGHORN_RENDER_PARALLEL is enabled, finds OpenMP and links it if found; otherwise warns that parallel rendering is disabled. ```cmake if(SLUGHORN_RENDER_PARALLEL) find_package(OpenMP QUIET) if(OpenMP_CXX_FOUND) target_compile_definitions(slughorn PUBLIC SLUGHORN_HAS_PARALLEL) target_link_libraries(slughorn PUBLIC OpenMP::OpenMP_CXX) message(STATUS "SLUGHORN_RENDER_PARALLEL: using OpenMP") else() message(WARNING "SLUGHORN_RENDER_PARALLEL=ON but OpenMP not found; parallel rendering disabled") endif() endif() ``` -------------------------------- ### Utility functions and emoji.hpp parser Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Provides basename and status setter, and parses emoji.hpp entries into a sorted array. ```javascript function basename(path) { return path.split("/").pop(); } function setStatus(text) { statusEl.textContent = text; } function parseEmojiHpp(text) { const out = []; const re = /\{\s*"([^"]+)"\s*,\s*0x([0-9A-Fa-f]+)\s*\}/g; let match; while((match = re.exec(text)) !== null) { out.push([match[1], parseInt(match[2], 16)]); } out.sort((a, b) => a[0].localeCompare(b[0])); return out; } ``` -------------------------------- ### Configure slughorn test executables and CTest Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt CMake test configuration for the slughorn project. It conditionally builds slughorn-test-bands when SLUGHORN_SERIAL is enabled, always builds slughorn-test-scanlinesweep, and registers a CTest test named scanlinesweep. The GDAL, SQLite3, ZLIB, and mapbox test blocks are commented out. ```cmake # ============================================================================= # GDAL (optional) # pkg_check_modules(GDAL IMPORTED_TARGET gdal) # # if(GDAL_FOUND AND SLUGHORN_SERIAL) # add_executable(slughorn-test-gdal "test/slughorn-test-gdal.cpp") # target_link_libraries(slughorn-test-gdal PRIVATE slughorn PkgConfig::GDAL) # target_compile_options(slughorn-test-gdal PRIVATE ${SLUGHORN_COMPILE_OPTIONS}) # message(STATUS "slughorn tests: GDAL found, building slughorn-test-gdal") # elseif(NOT GDAL_FOUND) # message(STATUS "slughorn tests: GDAL not found, skipping slughorn-test-gdal") # else() # message(STATUS "slughorn tests: SLUGHORN_SERIAL=OFF, skipping slughorn-test-gdal") # endif() # find_package(SQLite3 REQUIRED) # find_package(ZLIB REQUIRED) # add_executable(slughorn-test-mapbox "test/slughorn-test-mapbox.cpp") # target_link_libraries(slughorn-test-mapbox PRIVATE slughorn SQLite::SQLite3 ZLIB::ZLIB) # target_compile_options(slughorn-test-mapbox PRIVATE ${SLUGHORN_COMPILE_OPTIONS}) # target_include_directories(slughorn-test-mapbox PRIVATE # "${CMAKE_CURRENT_SOURCE_DIR}/../protozero/include" # "${CMAKE_CURRENT_SOURCE_DIR}/../vtzero/include" # ) if(SLUGHORN_SERIAL) add_executable(slughorn-test-bands "test/slughorn-test-bands.cpp") target_link_libraries(slughorn-test-bands PRIVATE slughorn) target_compile_options(slughorn-test-bands PRIVATE ${SLUGHORN_COMPILE_OPTIONS}) message(STATUS "slughorn tests: serial found, building slughorn-test-bands") else() message(STATUS "slughorn tests: SLUGHORN_SERIAL=OFF, skipping slughorn-test-bands") endif() add_executable(slughorn-test-scanlinesweep "test/slughorn-test-scanlinesweep.cpp") target_link_libraries(slughorn-test-scanlinesweep PRIVATE slughorn) target_compile_options(slughorn-test-scanlinesweep PRIVATE ${SLUGHORN_COMPILE_OPTIONS}) add_test(NAME scanlinesweep COMMAND slughorn-test-scanlinesweep) endif() ``` -------------------------------- ### Define SLUGHORN_GLFW option Source: https://github.com/alphapixel/slughorn/blob/main/CMakeLists.txt Defines the SLUGHORN_GLFW option, defaulting to OFF, to conditionally include GLFW support in the build. ```cmake option(SLUGHORN_GLFW "Include GLFW support (requires glfw3)" OFF) ``` -------------------------------- ### Load selected font Source: https://github.com/alphapixel/slughorn/blob/main/test/slughorn-test-emoji.html Loads the selected font using FontFace API, updates the CSS variable, and handles load failures. ```javascript async function loadSelectedFont() { const url = fontSelect.value; fontSourceLabel = url; try { if(currentFontFace) { document.fonts.delete(currentFontFace); currentFontFace = null; } const family = "SlughornEmojiTest"; const face = new FontFace(family, `url("${url}")`); await face.load(); document.fonts.add(face); currentFontFace = face; currentFontFamily = family; document.documentElement.style.setProperty("--emoji-font", `"${family}"`); setStatus(`Loaded font: ${url}`); } catch(err) { currentFontFamily = "system-ui"; document.documentElement.style.setProperty("--emoji-font", "system-ui"); setStatus(`Font load failed: ${url} — `); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.