Add support for OpenSans and font-awesome fonts.

PiperOrigin-RevId: 833666932
Change-Id: I5f0207c3331705b9078a1297b3e7b2a8d363ad60
This commit is contained in:
Haroon Qureshi
2025-11-17 23:13:59 -08:00
committed by Copybara-Service
parent 695e4c4038
commit 8077a6819c
6 changed files with 141 additions and 9 deletions
+31
View File
@@ -0,0 +1,31 @@
# Copyright 2025 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(MUJOCO_DEP_VERSION_font_awesome
a8386aae19e200ddb0f6845b5feeee5eb7013687
CACHE STRING "Tag/version of `font_awesome` to be fetched."
)
mark_as_advanced(MUJOCO_DEP_VERSION_font_awesome)
include(FindOrFetch)
fetchpackage(
PACKAGE_NAME font_awesome
GIT_REPO https://github.com/FortAwesome/Font-Awesome.git
GIT_TAG ${MUJOCO_DEP_VERSION_font_awesome}
PATCH_COMMAND
"cp"
"${CMAKE_SOURCE_DIR}/cmake/third_party_deps/font_awesome/CMakeLists.txt"
"${FETCHCONTENT_BASE_DIR}/font_awesome-src/CMakeLists.txt"
)
@@ -0,0 +1,15 @@
# Copyright 2025 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Data-only package.
+31
View File
@@ -0,0 +1,31 @@
# Copyright 2025 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(MUJOCO_DEP_VERSION_opensans
3d45774008254746e09bce4f8922b515a7b6a26b
CACHE STRING "Tag/version of `opensans` to be fetched."
)
mark_as_advanced(MUJOCO_DEP_VERSION_opensans)
include(FindOrFetch)
fetchpackage(
PACKAGE_NAME opensans
GIT_REPO https://github.com/googlefonts/opensans.git
GIT_TAG ${MUJOCO_DEP_VERSION_opensans}
PATCH_COMMAND
"cp"
"${CMAKE_SOURCE_DIR}/cmake/third_party_deps/opensans/CMakeLists.txt"
"${FETCHCONTENT_BASE_DIR}/opensans-src/CMakeLists.txt"
)
@@ -0,0 +1,15 @@
# Copyright 2025 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Data-only package.
+28 -9
View File
@@ -56,6 +56,9 @@ endif()
include(third_party_deps/dear_imgui)
include(third_party_deps/implot)
include(third_party_deps/opensans)
include(third_party_deps/font_awesome)
target_link_libraries(${MUJOCO_STUDIO_TARGET_NAME}
PRIVATE
${MUJOCO_STUDIO_RENDER_DEPS}
@@ -68,20 +71,36 @@ target_link_libraries(${MUJOCO_STUDIO_TARGET_NAME}
mujoco::toolbox
)
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)
add_custom_command(
TARGET ${MUJOCO_STUDIO_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../_deps/opensans-src/fonts/ttf/OpenSans-Regular.ttf
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets
COMMENT "Copying OpenSans-Regular.ttf assets to build directory"
)
add_custom_command(
TARGET ${MUJOCO_STUDIO_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../_deps/font_awesome-src/fonts/fontawesome-webfont.ttf
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets
COMMENT "Copying fontawesome-webfont.ttf to build directory"
)
# Filament backend requires additional files to be copied into an "assets" folder.
if(MUJOCO_USE_FILAMENT)
if(WIN32)
# Copy to work around lack of symlink permissions on Windows.
set(COPY_COMMAND copy_directory)
else()
set(COPY_COMMAND create_symlink)
endif()
add_custom_command(
TARGET ${MUJOCO_STUDIO_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E ${COPY_COMMAND}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../src/experimental/filament/assets
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets
COMMAND ${CMAKE_COMMAND}
-E copy_directory
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../src/experimental/filament/assets
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets
COMMENT "Copying Filament assets to build directory"
)
endif()
+21
View File
@@ -45,6 +45,27 @@ static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn) {
ImGui::StyleColorsDark();
ImGui_ImplSDL2_InitForOther(window);
#ifndef __EMSCRIPTEN__
// TODO: Get font loading working for wasm.
ImFontConfig main_cfg;
main_cfg.OversampleH = 8;
main_cfg.OversampleV = 4;
main_cfg.GlyphExtraSpacing.x = 0.3f;
auto main_font = load_asset_fn("OpenSans-Regular.ttf");
io.Fonts->AddFontFromMemoryTTF(main_font.data(), main_font.size(), 18.f,
&main_cfg);
ImFontConfig icon_cfg;
icon_cfg.OversampleH = 3;
icon_cfg.OversampleV = 3;
icon_cfg.MergeMode = true;
icon_cfg.GlyphMinAdvanceX = 14.0f;
auto icon_font = load_asset_fn("fontawesome-webfont.ttf");
constexpr ImWchar icon_ranges[] = {0xf000, 0xf3ff, 0x000};
io.Fonts->AddFontFromMemoryTTF(icon_font.data(), icon_font.size(), 14.f,
&icon_cfg, icon_ranges);
#endif
io.Fonts->Build();
}