feat: updated godot version
This commit is contained in:
parent
0c508b0831
commit
42b028dbb5
4694 changed files with 236470 additions and 401376 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="TextServerFallback" inherits="TextServerExtension" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="TextServerFallback" inherits="TextServerExtension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
A fallback implementation of Godot's text server, without support for BiDi and complex text layout.
|
||||
</brief_description>
|
||||
|
|
|
|||
312
engine/modules/text_server_fb/gdextension_build/SConstruct
Normal file
312
engine/modules/text_server_fb/gdextension_build/SConstruct
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
#!/usr/bin/env python
|
||||
# ruff: noqa: F821
|
||||
|
||||
import methods
|
||||
|
||||
# For the reference:
|
||||
# - CCFLAGS are compilation flags shared between C and C++
|
||||
# - CFLAGS are for C-specific compilation flags
|
||||
# - CXXFLAGS are for C++-specific compilation flags
|
||||
# - CPPFLAGS are for pre-processor flags
|
||||
# - CPPDEFINES are for pre-processor defines
|
||||
# - LINKFLAGS are for linking flags
|
||||
|
||||
env = SConscript("./godot-cpp/SConstruct")
|
||||
env.__class__.disable_warnings = methods.disable_warnings
|
||||
|
||||
opts = Variables([], ARGUMENTS)
|
||||
opts.Add(BoolVariable("brotli_enabled", "Use Brotli library", True))
|
||||
opts.Add(BoolVariable("freetype_enabled", "Use FreeType library", True))
|
||||
opts.Add(BoolVariable("msdfgen_enabled", "Use MSDFgen library (require FreeType)", True))
|
||||
opts.Add(BoolVariable("thorvg_enabled", "Use ThorVG library (require FreeType)", True))
|
||||
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
|
||||
|
||||
opts.Update(env)
|
||||
|
||||
# ThorVG
|
||||
if env["thorvg_enabled"] and env["freetype_enabled"]:
|
||||
env_tvg = env.Clone()
|
||||
env_tvg.disable_warnings()
|
||||
|
||||
thirdparty_tvg_dir = "../../../thirdparty/thorvg/"
|
||||
thirdparty_tvg_sources = [
|
||||
# common
|
||||
"src/common/tvgCompressor.cpp",
|
||||
"src/common/tvgLines.cpp",
|
||||
"src/common/tvgMath.cpp",
|
||||
"src/common/tvgStr.cpp",
|
||||
# SVG parser
|
||||
"src/loaders/svg/tvgSvgCssStyle.cpp",
|
||||
"src/loaders/svg/tvgSvgLoader.cpp",
|
||||
"src/loaders/svg/tvgSvgPath.cpp",
|
||||
"src/loaders/svg/tvgSvgSceneBuilder.cpp",
|
||||
"src/loaders/svg/tvgSvgUtil.cpp",
|
||||
"src/loaders/svg/tvgXmlParser.cpp",
|
||||
"src/loaders/raw/tvgRawLoader.cpp",
|
||||
# image loaders
|
||||
"src/loaders/external_png/tvgPngLoader.cpp",
|
||||
"src/loaders/jpg/tvgJpgd.cpp",
|
||||
"src/loaders/jpg/tvgJpgLoader.cpp",
|
||||
# renderer common
|
||||
"src/renderer/tvgAccessor.cpp",
|
||||
# "src/renderer/tvgAnimation.cpp",
|
||||
"src/renderer/tvgCanvas.cpp",
|
||||
"src/renderer/tvgFill.cpp",
|
||||
# "src/renderer/tvgGlCanvas.cpp",
|
||||
"src/renderer/tvgInitializer.cpp",
|
||||
"src/renderer/tvgLoader.cpp",
|
||||
"src/renderer/tvgPaint.cpp",
|
||||
"src/renderer/tvgPicture.cpp",
|
||||
"src/renderer/tvgRender.cpp",
|
||||
# "src/renderer/tvgSaver.cpp",
|
||||
"src/renderer/tvgScene.cpp",
|
||||
"src/renderer/tvgShape.cpp",
|
||||
"src/renderer/tvgSwCanvas.cpp",
|
||||
"src/renderer/tvgTaskScheduler.cpp",
|
||||
"src/renderer/tvgText.cpp",
|
||||
# "src/renderer/tvgWgCanvas.cpp",
|
||||
# renderer sw_engine
|
||||
"src/renderer/sw_engine/tvgSwFill.cpp",
|
||||
"src/renderer/sw_engine/tvgSwImage.cpp",
|
||||
"src/renderer/sw_engine/tvgSwMath.cpp",
|
||||
"src/renderer/sw_engine/tvgSwMemPool.cpp",
|
||||
"src/renderer/sw_engine/tvgSwRaster.cpp",
|
||||
"src/renderer/sw_engine/tvgSwRenderer.cpp",
|
||||
"src/renderer/sw_engine/tvgSwRle.cpp",
|
||||
"src/renderer/sw_engine/tvgSwShape.cpp",
|
||||
"src/renderer/sw_engine/tvgSwStroke.cpp",
|
||||
]
|
||||
thirdparty_tvg_sources = [thirdparty_tvg_dir + file for file in thirdparty_tvg_sources]
|
||||
|
||||
env_tvg.Append(
|
||||
CPPPATH=[
|
||||
"../../../thirdparty/thorvg/inc",
|
||||
"../../../thirdparty/thorvg/src/common",
|
||||
"../../../thirdparty/thorvg/src/renderer",
|
||||
"../../../thirdparty/thorvg/src/renderer/sw_engine",
|
||||
"../../../thirdparty/thorvg/src/loaders/svg",
|
||||
"../../../thirdparty/thorvg/src/loaders/raw",
|
||||
"../../../thirdparty/thorvg/src/loaders/external_png",
|
||||
"../../../thirdparty/thorvg/src/loaders/jpg",
|
||||
"../../../thirdparty/libpng",
|
||||
]
|
||||
)
|
||||
|
||||
# Enable ThorVG static object linking.
|
||||
env_tvg.Append(CPPDEFINES=["TVG_STATIC"])
|
||||
|
||||
env.Append(
|
||||
CPPPATH=[
|
||||
"../../../thirdparty/thorvg/inc",
|
||||
"../../../thirdparty/thorvg/src/common",
|
||||
"../../../thirdparty/thorvg/src/renderer",
|
||||
]
|
||||
)
|
||||
env.Append(CPPDEFINES=["MODULE_SVG_ENABLED"])
|
||||
|
||||
lib = env_tvg.Library(
|
||||
f"tvg_builtin{env['suffix']}{env['LIBSUFFIX']}",
|
||||
thirdparty_tvg_sources,
|
||||
)
|
||||
env.Append(LIBS=[lib])
|
||||
|
||||
# MSDFGEN
|
||||
if env["msdfgen_enabled"] and env["freetype_enabled"]:
|
||||
env_msdfgen = env.Clone()
|
||||
env_msdfgen.disable_warnings()
|
||||
|
||||
thirdparty_msdfgen_dir = "../../../thirdparty/msdfgen/"
|
||||
thirdparty_msdfgen_sources = [
|
||||
"core/Contour.cpp",
|
||||
"core/DistanceMapping.cpp",
|
||||
"core/EdgeHolder.cpp",
|
||||
"core/MSDFErrorCorrection.cpp",
|
||||
"core/Projection.cpp",
|
||||
"core/Scanline.cpp",
|
||||
"core/Shape.cpp",
|
||||
"core/contour-combiners.cpp",
|
||||
"core/convergent-curve-ordering.cpp",
|
||||
"core/edge-coloring.cpp",
|
||||
"core/edge-segments.cpp",
|
||||
"core/edge-selectors.cpp",
|
||||
"core/equation-solver.cpp",
|
||||
# "core/export-svg.cpp",
|
||||
"core/msdf-error-correction.cpp",
|
||||
"core/msdfgen.cpp",
|
||||
"core/rasterization.cpp",
|
||||
"core/render-sdf.cpp",
|
||||
# "core/save-bmp.cpp",
|
||||
# "core/save-fl32.cpp",
|
||||
# "core/save-rgba.cpp",
|
||||
# "core/save-tiff.cpp",
|
||||
"core/sdf-error-estimation.cpp",
|
||||
"core/shape-description.cpp",
|
||||
]
|
||||
thirdparty_msdfgen_sources = [thirdparty_msdfgen_dir + file for file in thirdparty_msdfgen_sources]
|
||||
|
||||
env_msdfgen.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")])
|
||||
env_msdfgen.Append(CPPPATH=["../../../thirdparty/freetype/include", "../../../thirdparty/msdfgen"])
|
||||
env.Append(CPPPATH=["../../../thirdparty/msdfgen"])
|
||||
env.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")])
|
||||
env.Append(CPPDEFINES=["MODULE_MSDFGEN_ENABLED"])
|
||||
|
||||
lib = env_msdfgen.Library(
|
||||
f"msdfgen_builtin{env['suffix']}{env['LIBSUFFIX']}",
|
||||
thirdparty_msdfgen_sources,
|
||||
)
|
||||
env.Append(LIBS=[lib])
|
||||
|
||||
# FreeType
|
||||
if env["freetype_enabled"]:
|
||||
env_freetype = env.Clone()
|
||||
env_freetype.disable_warnings()
|
||||
|
||||
thirdparty_freetype_dir = "../../../thirdparty/freetype/"
|
||||
thirdparty_freetype_sources = [
|
||||
"src/autofit/autofit.c",
|
||||
"src/base/ftbase.c",
|
||||
"src/base/ftbbox.c",
|
||||
"src/base/ftbdf.c",
|
||||
"src/base/ftbitmap.c",
|
||||
"src/base/ftcid.c",
|
||||
"src/base/ftdebug.c",
|
||||
"src/base/ftfstype.c",
|
||||
"src/base/ftgasp.c",
|
||||
"src/base/ftglyph.c",
|
||||
"src/base/ftgxval.c",
|
||||
"src/base/ftinit.c",
|
||||
"src/base/ftmm.c",
|
||||
"src/base/ftotval.c",
|
||||
"src/base/ftpatent.c",
|
||||
"src/base/ftpfr.c",
|
||||
"src/base/ftstroke.c",
|
||||
"src/base/ftsynth.c",
|
||||
"src/base/ftsystem.c",
|
||||
"src/base/fttype1.c",
|
||||
"src/base/ftwinfnt.c",
|
||||
"src/bdf/bdf.c",
|
||||
"src/bzip2/ftbzip2.c",
|
||||
"src/cache/ftcache.c",
|
||||
"src/cff/cff.c",
|
||||
"src/cid/type1cid.c",
|
||||
"src/gxvalid/gxvalid.c",
|
||||
"src/gzip/ftgzip.c",
|
||||
"src/lzw/ftlzw.c",
|
||||
"src/otvalid/otvalid.c",
|
||||
"src/pcf/pcf.c",
|
||||
"src/pfr/pfr.c",
|
||||
"src/psaux/psaux.c",
|
||||
"src/pshinter/pshinter.c",
|
||||
"src/psnames/psnames.c",
|
||||
"src/raster/raster.c",
|
||||
"src/sdf/sdf.c",
|
||||
"src/svg/svg.c",
|
||||
"src/smooth/smooth.c",
|
||||
"src/truetype/truetype.c",
|
||||
"src/type1/type1.c",
|
||||
"src/type42/type42.c",
|
||||
"src/winfonts/winfnt.c",
|
||||
"src/sfnt/sfnt.c",
|
||||
]
|
||||
thirdparty_freetype_sources = [thirdparty_freetype_dir + file for file in thirdparty_freetype_sources]
|
||||
|
||||
thirdparty_png_dir = "../../../thirdparty/libpng/"
|
||||
thirdparty_png_sources = [
|
||||
"png.c",
|
||||
"pngerror.c",
|
||||
"pngget.c",
|
||||
"pngmem.c",
|
||||
"pngpread.c",
|
||||
"pngread.c",
|
||||
"pngrio.c",
|
||||
"pngrtran.c",
|
||||
"pngrutil.c",
|
||||
"pngset.c",
|
||||
"pngtrans.c",
|
||||
"pngwio.c",
|
||||
"pngwrite.c",
|
||||
"pngwtran.c",
|
||||
"pngwutil.c",
|
||||
]
|
||||
thirdparty_freetype_sources += [thirdparty_png_dir + file for file in thirdparty_png_sources]
|
||||
|
||||
thirdparty_zlib_dir = "../../../thirdparty/zlib/"
|
||||
thirdparty_zlib_sources = [
|
||||
"adler32.c",
|
||||
"compress.c",
|
||||
"crc32.c",
|
||||
"deflate.c",
|
||||
"inffast.c",
|
||||
"inflate.c",
|
||||
"inftrees.c",
|
||||
"trees.c",
|
||||
"uncompr.c",
|
||||
"zutil.c",
|
||||
]
|
||||
thirdparty_freetype_sources += [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
|
||||
|
||||
if env["brotli_enabled"]:
|
||||
thirdparty_brotli_dir = "../../../thirdparty/brotli/"
|
||||
thirdparty_brotli_sources = [
|
||||
"common/constants.c",
|
||||
"common/context.c",
|
||||
"common/dictionary.c",
|
||||
"common/platform.c",
|
||||
"common/shared_dictionary.c",
|
||||
"common/transform.c",
|
||||
"dec/bit_reader.c",
|
||||
"dec/decode.c",
|
||||
"dec/huffman.c",
|
||||
"dec/state.c",
|
||||
]
|
||||
thirdparty_freetype_sources += [thirdparty_brotli_dir + file for file in thirdparty_brotli_sources]
|
||||
env_freetype.Append(CPPDEFINES=["FT_CONFIG_OPTION_USE_BROTLI"])
|
||||
env_freetype.Prepend(CPPPATH=[thirdparty_brotli_dir + "include"])
|
||||
env.Append(CPPDEFINES=["FT_CONFIG_OPTION_USE_BROTLI"])
|
||||
|
||||
env_freetype.Append(CPPPATH=[thirdparty_freetype_dir + "/include", thirdparty_zlib_dir, thirdparty_png_dir])
|
||||
env.Append(CPPPATH=[thirdparty_freetype_dir + "/include"])
|
||||
|
||||
env_freetype.Append(
|
||||
CPPDEFINES=[
|
||||
"FT2_BUILD_LIBRARY",
|
||||
"FT_CONFIG_OPTION_USE_PNG",
|
||||
"FT_CONFIG_OPTION_SYSTEM_ZLIB",
|
||||
]
|
||||
)
|
||||
if env.dev_build:
|
||||
env_freetype.Append(CPPDEFINES=["ZLIB_DEBUG"])
|
||||
|
||||
env.Append(CPPDEFINES=["MODULE_FREETYPE_ENABLED"])
|
||||
|
||||
lib = env_freetype.Library(
|
||||
f"freetype_builtin{env['suffix']}{env['LIBSUFFIX']}",
|
||||
thirdparty_freetype_sources,
|
||||
)
|
||||
env.Append(LIBS=[lib])
|
||||
|
||||
|
||||
env.Append(CPPDEFINES=["GDEXTENSION"])
|
||||
env.Append(CPPPATH=["../"])
|
||||
sources = Glob("../*.cpp")
|
||||
|
||||
if env["platform"] == "macos":
|
||||
methods.write_macos_plist(
|
||||
f"./bin/libtextserver_fallback.macos.{env['target']}.framework",
|
||||
f"libtextserver_fallback.macos.{env['target']}",
|
||||
"org.godotengine.textserver_fallback",
|
||||
"Fallback Text Server",
|
||||
)
|
||||
library = env.SharedLibrary(
|
||||
f"./bin/libtextserver_fallback.macos.{env['target']}.framework/libtextserver_fallback.macos.{env['target']}",
|
||||
source=sources,
|
||||
)
|
||||
else:
|
||||
library = env.SharedLibrary(
|
||||
f"./bin/libtextserver_fallback{env['suffix']}{env['SHLIBSUFFIX']}",
|
||||
source=sources,
|
||||
)
|
||||
|
||||
Default(library)
|
||||
|
||||
methods.prepare_timer()
|
||||
60
engine/modules/text_server_fb/gdextension_build/methods.py
Normal file
60
engine/modules/text_server_fb/gdextension_build/methods.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
def disable_warnings(self):
|
||||
# 'self' is the environment
|
||||
if self["platform"] == "windows" and not self["use_mingw"]:
|
||||
# We have to remove existing warning level defines before appending /w,
|
||||
# otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
|
||||
WARN_FLAGS = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/W0"]
|
||||
self["CCFLAGS"] = [x for x in self["CCFLAGS"] if x not in WARN_FLAGS]
|
||||
self["CFLAGS"] = [x for x in self["CFLAGS"] if x not in WARN_FLAGS]
|
||||
self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if x not in WARN_FLAGS]
|
||||
self.AppendUnique(CCFLAGS=["/w"])
|
||||
else:
|
||||
self.AppendUnique(CCFLAGS=["-w"])
|
||||
|
||||
|
||||
def prepare_timer():
|
||||
import atexit
|
||||
import time
|
||||
|
||||
def print_elapsed_time(time_at_start: float):
|
||||
time_elapsed = time.time() - time_at_start
|
||||
time_formatted = time.strftime("%H:%M:%S", time.gmtime(time_elapsed))
|
||||
time_centiseconds = round((time_elapsed % 1) * 100)
|
||||
print(f"[Time elapsed: {time_formatted}.{time_centiseconds}]")
|
||||
|
||||
atexit.register(print_elapsed_time, time.time())
|
||||
|
||||
|
||||
def write_macos_plist(target, binary_name, identifier, name):
|
||||
import os
|
||||
|
||||
os.makedirs(f"{target}/Resource/", exist_ok=True)
|
||||
with open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n") as f:
|
||||
f.write(f"""\
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{binary_name}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>{identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>{name}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0.0</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.14</string>
|
||||
</dict>
|
||||
</plist>
|
||||
""")
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
[configuration]
|
||||
|
||||
entry_symbol = "textserver_fallback_init"
|
||||
|
||||
[libraries]
|
||||
|
||||
linux.x86_64.debug = "bin/libtextserver_fallback.linux.template_debug.x86_64.so"
|
||||
linux.x86_64.release = "bin/libtextserver_fallback.linux.template_release.x86_64.so"
|
||||
linux.x86_32.debug = "bin/libtextserver_fallback.linux.template_debug.x86_32.so"
|
||||
linux.x86_32.release = "bin/libtextserver_fallback.linux.template_release.x86_32.so"
|
||||
linux.arm64.debug = "bin/libtextserver_fallback.linux.template_debug.arm64.so"
|
||||
linux.arm64.release = "bin/libtextserver_fallback.linux.template_release.arm64.so"
|
||||
linux.rv64.debug = "bin/libtextserver_fallback.linux.template_debug.rv64.so"
|
||||
linux.rv64.release = "bin/libtextserver_fallback.linux.template_release.rv64.so"
|
||||
|
||||
windows.x86_64.debug = "bin/libtextserver_fallback.windows.template_debug.x86_64.dll"
|
||||
windows.x86_64.release = "bin/libtextserver_fallback.windows.template_release.x86_64.dll"
|
||||
windows.x86_32.debug = "bin/libtextserver_fallback.windows.template_debug.x86_32.dll"
|
||||
windows.x86_32.release = "bin/libtextserver_fallback.windows.template_release.x86_32.dll"
|
||||
windows.arm64.debug = "bin/libtextserver_fallback.windows.template_debug.arm64.dll"
|
||||
windows.arm64.release = "bin/libtextserver_fallback.windows.template_release.arm64.dll"
|
||||
|
||||
macos.debug = "bin/libtextserver_fallback.macos.template_debug.framework"
|
||||
macos.release = "bin/libtextserver_fallback.macos.template_release.framework"
|
||||
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
#include "text_server_fb.h"
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
|
||||
void initialize_text_server_fb_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
|
||||
return;
|
||||
|
|
@ -53,3 +51,27 @@ void uninitialize_text_server_fb_module(ModuleInitializationLevel p_level) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GDEXTENSION
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
#include <godot_cpp/core/memory.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
extern "C" {
|
||||
|
||||
GDExtensionBool GDE_EXPORT textserver_fallback_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
||||
GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
|
||||
|
||||
init_obj.register_initializer(&initialize_text_server_fb_module);
|
||||
init_obj.register_terminator(&uninitialize_text_server_fb_module);
|
||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SERVERS);
|
||||
|
||||
return init_obj.init();
|
||||
}
|
||||
|
||||
} // ! extern "C"
|
||||
|
||||
#endif // ! GDEXTENSION
|
||||
|
|
|
|||
|
|
@ -30,7 +30,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifdef GDEXTENSION
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
using namespace godot;
|
||||
#elif defined(GODOT_MODULE)
|
||||
#include "modules/register_module_types.h"
|
||||
#endif
|
||||
|
||||
void initialize_text_server_fb_module(ModuleInitializationLevel p_level);
|
||||
void uninitialize_text_server_fb_module(ModuleInitializationLevel p_level);
|
||||
|
|
|
|||
|
|
@ -30,18 +30,36 @@
|
|||
|
||||
#include "text_server_fb.h"
|
||||
|
||||
#ifdef GDEXTENSION
|
||||
// Headers for building as GDExtension plug-in.
|
||||
|
||||
#include <godot_cpp/classes/file_access.hpp>
|
||||
#include <godot_cpp/classes/os.hpp>
|
||||
#include <godot_cpp/classes/project_settings.hpp>
|
||||
#include <godot_cpp/classes/rendering_server.hpp>
|
||||
#include <godot_cpp/classes/translation_server.hpp>
|
||||
#include <godot_cpp/core/error_macros.hpp>
|
||||
|
||||
#define OT_TAG(m_c1, m_c2, m_c3, m_c4) ((int32_t)((((uint32_t)(m_c1) & 0xff) << 24) | (((uint32_t)(m_c2) & 0xff) << 16) | (((uint32_t)(m_c3) & 0xff) << 8) | ((uint32_t)(m_c4) & 0xff)))
|
||||
|
||||
using namespace godot;
|
||||
|
||||
#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get_setting_with_override(m_var)
|
||||
|
||||
#elif defined(GODOT_MODULE)
|
||||
// Headers for building as built-in module.
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/math/math_funcs_binary.h"
|
||||
#include "core/object/callable_mp.h"
|
||||
#include "core/object/worker_thread_pool.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/string/print_string.h"
|
||||
#include "core/string/translation_server.h"
|
||||
#include "servers/rendering/rendering_server.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h" // For freetype, msdfgen, svg.
|
||||
|
||||
#endif
|
||||
|
||||
// Thirdparty headers.
|
||||
|
||||
#ifdef MODULE_MSDFGEN_ENABLED
|
||||
|
|
@ -86,7 +104,11 @@ bool TextServerFallback::_has_feature(Feature p_feature) const {
|
|||
}
|
||||
|
||||
String TextServerFallback::_get_name() const {
|
||||
#ifdef GDEXTENSION
|
||||
return "Fallback (GDExtension)";
|
||||
#elif defined(GODOT_MODULE)
|
||||
return "Fallback (Built-in)";
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t TextServerFallback::_get_features() const {
|
||||
|
|
@ -265,7 +287,7 @@ _FORCE_INLINE_ TextServerFallback::FontTexturePosition TextServerFallback::find_
|
|||
// Could not find texture to fit, create one.
|
||||
int texsize = MAX(p_data->size.x * 0.125, 256);
|
||||
|
||||
texsize = Math::next_power_of_2((uint32_t)texsize);
|
||||
texsize = next_power_of_2((uint32_t)texsize);
|
||||
|
||||
if (p_msdf) {
|
||||
texsize = MIN(texsize, 2048);
|
||||
|
|
@ -273,10 +295,10 @@ _FORCE_INLINE_ TextServerFallback::FontTexturePosition TextServerFallback::find_
|
|||
texsize = MIN(texsize, 1024);
|
||||
}
|
||||
if (mw > texsize) { // Special case, adapt to it?
|
||||
texsize = Math::next_power_of_2((uint32_t)mw);
|
||||
texsize = next_power_of_2((uint32_t)mw);
|
||||
}
|
||||
if (mh > texsize) { // Special case, adapt to it?
|
||||
texsize = Math::next_power_of_2((uint32_t)mh);
|
||||
texsize = next_power_of_2((uint32_t)mh);
|
||||
}
|
||||
|
||||
ShelfPackTexture tex = ShelfPackTexture(texsize, texsize);
|
||||
|
|
@ -659,7 +681,7 @@ bool TextServerFallback::_ensure_glyph(FontFallback *p_font_data, const Vector2i
|
|||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
FontGlyph gl;
|
||||
if (p_font_data->face) {
|
||||
if (fd->face) {
|
||||
FT_Int32 flags = FT_LOAD_DEFAULT;
|
||||
|
||||
bool outline = p_size.y > 0;
|
||||
|
|
@ -677,19 +699,19 @@ bool TextServerFallback::_ensure_glyph(FontFallback *p_font_data, const Vector2i
|
|||
if (p_font_data->force_autohinter) {
|
||||
flags |= FT_LOAD_FORCE_AUTOHINT;
|
||||
}
|
||||
if (outline || (p_font_data->disable_embedded_bitmaps && !FT_HAS_COLOR(p_font_data->face))) {
|
||||
if (outline || (p_font_data->disable_embedded_bitmaps && !FT_HAS_COLOR(fd->face))) {
|
||||
flags |= FT_LOAD_NO_BITMAP;
|
||||
} else if (FT_HAS_COLOR(p_font_data->face)) {
|
||||
} else if (FT_HAS_COLOR(fd->face)) {
|
||||
flags |= FT_LOAD_COLOR;
|
||||
}
|
||||
|
||||
glyph_index = FT_Get_Char_Index(p_font_data->face, glyph_index);
|
||||
glyph_index = FT_Get_Char_Index(fd->face, glyph_index);
|
||||
|
||||
FT_Fixed v, h;
|
||||
FT_Get_Advance(p_font_data->face, glyph_index, flags, &h);
|
||||
FT_Get_Advance(p_font_data->face, glyph_index, flags | FT_LOAD_VERTICAL_LAYOUT, &v);
|
||||
FT_Get_Advance(fd->face, glyph_index, flags, &h);
|
||||
FT_Get_Advance(fd->face, glyph_index, flags | FT_LOAD_VERTICAL_LAYOUT, &v);
|
||||
|
||||
int error = FT_Load_Glyph(p_font_data->face, glyph_index, flags);
|
||||
int error = FT_Load_Glyph(fd->face, glyph_index, flags);
|
||||
if (error) {
|
||||
E = fd->glyph_map.insert(p_glyph, FontGlyph());
|
||||
r_glyph = E->value;
|
||||
|
|
@ -699,21 +721,21 @@ bool TextServerFallback::_ensure_glyph(FontFallback *p_font_data, const Vector2i
|
|||
if (!p_font_data->msdf) {
|
||||
if ((p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && p_size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE * 64)) {
|
||||
FT_Pos xshift = (int)((p_glyph >> 27) & 3) << 4;
|
||||
FT_Outline_Translate(&p_font_data->face->glyph->outline, xshift, 0);
|
||||
FT_Outline_Translate(&fd->face->glyph->outline, xshift, 0);
|
||||
} else if ((p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (p_font_data->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && p_size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE * 64)) {
|
||||
FT_Pos xshift = (int)((p_glyph >> 27) & 3) << 5;
|
||||
FT_Outline_Translate(&p_font_data->face->glyph->outline, xshift, 0);
|
||||
FT_Outline_Translate(&fd->face->glyph->outline, xshift, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (p_font_data->embolden != 0.f) {
|
||||
FT_Pos strength = p_font_data->embolden * p_size.x / 16; // 26.6 fractional units (1 / 64).
|
||||
FT_Outline_Embolden(&p_font_data->face->glyph->outline, strength);
|
||||
FT_Outline_Embolden(&fd->face->glyph->outline, strength);
|
||||
}
|
||||
|
||||
if (p_font_data->transform != Transform2D()) {
|
||||
FT_Matrix mat = { FT_Fixed(p_font_data->transform[0][0] * 65536), FT_Fixed(p_font_data->transform[0][1] * 65536), FT_Fixed(p_font_data->transform[1][0] * 65536), FT_Fixed(p_font_data->transform[1][1] * 65536) }; // 16.16 fractional units (1 / 65536).
|
||||
FT_Outline_Transform(&p_font_data->face->glyph->outline, &mat);
|
||||
FT_Outline_Transform(&fd->face->glyph->outline, &mat);
|
||||
}
|
||||
|
||||
FT_Render_Mode aa_mode = FT_RENDER_MODE_NORMAL;
|
||||
|
|
@ -751,7 +773,7 @@ bool TextServerFallback::_ensure_glyph(FontFallback *p_font_data, const Vector2i
|
|||
} break;
|
||||
}
|
||||
|
||||
FT_GlyphSlot slot = p_font_data->face->glyph;
|
||||
FT_GlyphSlot slot = fd->face->glyph;
|
||||
bool from_svg = (slot->format == FT_GLYPH_FORMAT_SVG); // Need to check before FT_Render_Glyph as it will change format to bitmap.
|
||||
if (!outline) {
|
||||
if (!p_font_data->msdf) {
|
||||
|
|
@ -780,7 +802,7 @@ bool TextServerFallback::_ensure_glyph(FontFallback *p_font_data, const Vector2i
|
|||
FT_Glyph glyph;
|
||||
FT_BitmapGlyph glyph_bitmap;
|
||||
|
||||
if (FT_Get_Glyph(p_font_data->face->glyph, &glyph) != 0) {
|
||||
if (FT_Get_Glyph(fd->face->glyph, &glyph) != 0) {
|
||||
goto cleanup_stroker;
|
||||
}
|
||||
if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) {
|
||||
|
|
@ -813,11 +835,6 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
|
|||
|
||||
HashMap<Vector2i, FontForSizeFallback *>::Iterator E = p_font_data->cache.find(p_size);
|
||||
if (E) {
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (E->value->fsize != nullptr) {
|
||||
FT_Activate_Size(E->value->fsize);
|
||||
}
|
||||
#endif
|
||||
r_cache_for_size = E->value;
|
||||
// Size used directly, remove from oversampling list.
|
||||
if (p_oversampling == 0 && E->value->viewport_oversampling != 0) {
|
||||
|
|
@ -853,44 +870,39 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
|
|||
#endif
|
||||
}
|
||||
|
||||
if (p_font_data->face == nullptr) {
|
||||
memset(&p_font_data->stream, 0, sizeof(FT_StreamRec));
|
||||
p_font_data->stream.base = (unsigned char *)p_font_data->data_ptr;
|
||||
p_font_data->stream.size = p_font_data->data_size;
|
||||
p_font_data->stream.pos = 0;
|
||||
memset(&fd->stream, 0, sizeof(FT_StreamRec));
|
||||
fd->stream.base = (unsigned char *)p_font_data->data_ptr;
|
||||
fd->stream.size = p_font_data->data_size;
|
||||
fd->stream.pos = 0;
|
||||
|
||||
FT_Open_Args fargs;
|
||||
memset(&fargs, 0, sizeof(FT_Open_Args));
|
||||
fargs.memory_base = (unsigned char *)p_font_data->data_ptr;
|
||||
fargs.memory_size = p_font_data->data_size;
|
||||
fargs.flags = FT_OPEN_MEMORY;
|
||||
fargs.stream = &p_font_data->stream;
|
||||
FT_Open_Args fargs;
|
||||
memset(&fargs, 0, sizeof(FT_Open_Args));
|
||||
fargs.memory_base = (unsigned char *)p_font_data->data_ptr;
|
||||
fargs.memory_size = p_font_data->data_size;
|
||||
fargs.flags = FT_OPEN_MEMORY;
|
||||
fargs.stream = &fd->stream;
|
||||
|
||||
int max_index = 0;
|
||||
FT_Face tmp_face = nullptr;
|
||||
error = FT_Open_Face(ft_library, &fargs, -1, &tmp_face);
|
||||
if (tmp_face && error == 0) {
|
||||
max_index = tmp_face->num_faces - 1;
|
||||
}
|
||||
if (tmp_face) {
|
||||
FT_Done_Face(tmp_face);
|
||||
}
|
||||
|
||||
error = FT_Open_Face(ft_library, &fargs, CLAMP(p_font_data->face_index, 0, max_index), &p_font_data->face);
|
||||
if (error) {
|
||||
FT_Done_Face(p_font_data->face);
|
||||
p_font_data->face = nullptr;
|
||||
memdelete(fd);
|
||||
if (p_silent) {
|
||||
return false;
|
||||
} else {
|
||||
ERR_FAIL_V_MSG(false, "FreeType: Error loading font: '" + String(FT_Error_String(error)) + "'.");
|
||||
}
|
||||
}
|
||||
int max_index = 0;
|
||||
FT_Face tmp_face = nullptr;
|
||||
error = FT_Open_Face(ft_library, &fargs, -1, &tmp_face);
|
||||
if (tmp_face && error == 0) {
|
||||
max_index = tmp_face->num_faces - 1;
|
||||
}
|
||||
if (tmp_face) {
|
||||
FT_Done_Face(tmp_face);
|
||||
}
|
||||
|
||||
FT_New_Size(p_font_data->face, &fd->fsize);
|
||||
FT_Activate_Size(fd->fsize);
|
||||
error = FT_Open_Face(ft_library, &fargs, CLAMP(p_font_data->face_index, 0, max_index), &fd->face);
|
||||
if (error) {
|
||||
FT_Done_Face(fd->face);
|
||||
fd->face = nullptr;
|
||||
memdelete(fd);
|
||||
if (p_silent) {
|
||||
return false;
|
||||
} else {
|
||||
ERR_FAIL_V_MSG(false, "FreeType: Error loading font: '" + String(FT_Error_String(error)) + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double sz = double(fd->size.x) / 64.0;
|
||||
|
|
@ -898,47 +910,47 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
|
|||
sz = p_font_data->msdf_source_size;
|
||||
}
|
||||
|
||||
if (FT_HAS_COLOR(p_font_data->face) && p_font_data->face->num_fixed_sizes > 0) {
|
||||
if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) {
|
||||
int best_match = 0;
|
||||
int diff = Math::abs(sz - ((int64_t)p_font_data->face->available_sizes[0].width));
|
||||
fd->scale = sz / p_font_data->face->available_sizes[0].width;
|
||||
for (int i = 1; i < p_font_data->face->num_fixed_sizes; i++) {
|
||||
int ndiff = Math::abs(sz - ((int64_t)p_font_data->face->available_sizes[i].width));
|
||||
int diff = Math::abs(sz - ((int64_t)fd->face->available_sizes[0].width));
|
||||
fd->scale = sz / fd->face->available_sizes[0].width;
|
||||
for (int i = 1; i < fd->face->num_fixed_sizes; i++) {
|
||||
int ndiff = Math::abs(sz - ((int64_t)fd->face->available_sizes[i].width));
|
||||
if (ndiff < diff) {
|
||||
best_match = i;
|
||||
diff = ndiff;
|
||||
fd->scale = sz / p_font_data->face->available_sizes[i].width;
|
||||
fd->scale = sz / fd->face->available_sizes[i].width;
|
||||
}
|
||||
}
|
||||
FT_Select_Size(p_font_data->face, best_match);
|
||||
FT_Select_Size(fd->face, best_match);
|
||||
} else {
|
||||
FT_Size_RequestRec req;
|
||||
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
|
||||
req.width = MIN(2048.0, sz) * 64.0;
|
||||
req.height = MIN(2048.0, sz) * 64.0;
|
||||
req.width = sz * 64.0;
|
||||
req.height = sz * 64.0;
|
||||
req.horiResolution = 0;
|
||||
req.vertResolution = 0;
|
||||
|
||||
FT_Request_Size(p_font_data->face, &req);
|
||||
if (p_font_data->face->size->metrics.y_ppem != 0) {
|
||||
fd->scale = sz / (double)p_font_data->face->size->metrics.y_ppem;
|
||||
FT_Request_Size(fd->face, &req);
|
||||
if (fd->face->size->metrics.y_ppem != 0) {
|
||||
fd->scale = sz / (double)fd->face->size->metrics.y_ppem;
|
||||
}
|
||||
}
|
||||
|
||||
fd->ascent = (p_font_data->face->size->metrics.ascender / 64.0) * fd->scale;
|
||||
fd->descent = (-p_font_data->face->size->metrics.descender / 64.0) * fd->scale;
|
||||
fd->underline_position = (-FT_MulFix(p_font_data->face->underline_position, p_font_data->face->size->metrics.y_scale) / 64.0) * fd->scale;
|
||||
fd->underline_thickness = (FT_MulFix(p_font_data->face->underline_thickness, p_font_data->face->size->metrics.y_scale) / 64.0) * fd->scale;
|
||||
fd->ascent = (fd->face->size->metrics.ascender / 64.0) * fd->scale;
|
||||
fd->descent = (-fd->face->size->metrics.descender / 64.0) * fd->scale;
|
||||
fd->underline_position = (-FT_MulFix(fd->face->underline_position, fd->face->size->metrics.y_scale) / 64.0) * fd->scale;
|
||||
fd->underline_thickness = (FT_MulFix(fd->face->underline_thickness, fd->face->size->metrics.y_scale) / 64.0) * fd->scale;
|
||||
|
||||
if (!p_font_data->face_init) {
|
||||
// When a font does not provide a `family_name`, FreeType tries to synthesize one based on other names.
|
||||
// FreeType automatically converts non-ASCII characters to "?" in the synthesized name.
|
||||
// To avoid that behavior, use the format-specific name directly if available.
|
||||
if (FT_IS_SFNT(p_font_data->face)) {
|
||||
int name_count = FT_Get_Sfnt_Name_Count(p_font_data->face);
|
||||
if (FT_IS_SFNT(fd->face)) {
|
||||
int name_count = FT_Get_Sfnt_Name_Count(fd->face);
|
||||
for (int i = 0; i < name_count; i++) {
|
||||
FT_SfntName sfnt_name;
|
||||
if (FT_Get_Sfnt_Name(p_font_data->face, i, &sfnt_name) != 0) {
|
||||
if (FT_Get_Sfnt_Name(fd->face, i, &sfnt_name) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (sfnt_name.name_id != TT_NAME_ID_FONT_FAMILY && sfnt_name.name_id != TT_NAME_ID_TYPOGRAPHIC_FAMILY) {
|
||||
|
|
@ -963,29 +975,29 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
|
|||
}
|
||||
}
|
||||
}
|
||||
if (p_font_data->font_name.is_empty() && p_font_data->face->family_name != nullptr) {
|
||||
p_font_data->font_name = String::utf8((const char *)p_font_data->face->family_name);
|
||||
if (p_font_data->font_name.is_empty() && fd->face->family_name != nullptr) {
|
||||
p_font_data->font_name = String::utf8((const char *)fd->face->family_name);
|
||||
}
|
||||
if (p_font_data->face->style_name != nullptr) {
|
||||
p_font_data->style_name = String::utf8((const char *)p_font_data->face->style_name);
|
||||
if (fd->face->style_name != nullptr) {
|
||||
p_font_data->style_name = String::utf8((const char *)fd->face->style_name);
|
||||
}
|
||||
p_font_data->weight = _font_get_weight_by_name(p_font_data->style_name.to_lower());
|
||||
p_font_data->stretch = _font_get_stretch_by_name(p_font_data->style_name.to_lower());
|
||||
p_font_data->style_flags = 0;
|
||||
if ((p_font_data->face->style_flags & FT_STYLE_FLAG_BOLD) || p_font_data->weight >= 700) {
|
||||
if ((fd->face->style_flags & FT_STYLE_FLAG_BOLD) || p_font_data->weight >= 700) {
|
||||
p_font_data->style_flags.set_flag(FONT_BOLD);
|
||||
}
|
||||
if ((p_font_data->face->style_flags & FT_STYLE_FLAG_ITALIC) || _is_ital_style(p_font_data->style_name.to_lower())) {
|
||||
if ((fd->face->style_flags & FT_STYLE_FLAG_ITALIC) || _is_ital_style(p_font_data->style_name.to_lower())) {
|
||||
p_font_data->style_flags.set_flag(FONT_ITALIC);
|
||||
}
|
||||
if (p_font_data->face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) {
|
||||
if (fd->face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) {
|
||||
p_font_data->style_flags.set_flag(FONT_FIXED_WIDTH);
|
||||
}
|
||||
// Read OpenType variations.
|
||||
p_font_data->supported_varaitions.clear();
|
||||
if (p_font_data->face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) {
|
||||
if (fd->face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) {
|
||||
FT_MM_Var *amaster;
|
||||
FT_Get_MM_Var(p_font_data->face, &amaster);
|
||||
FT_Get_MM_Var(fd->face, &amaster);
|
||||
for (FT_UInt i = 0; i < amaster->num_axis; i++) {
|
||||
p_font_data->supported_varaitions[(int32_t)amaster->axis[i].tag] = Vector3i(amaster->axis[i].minimum / 65536, amaster->axis[i].maximum / 65536, amaster->axis[i].def / 65536);
|
||||
}
|
||||
|
|
@ -998,8 +1010,8 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
|
|||
if (p_font_data->font_name == ".Apple Color Emoji UI" || p_font_data->font_name == "Apple Color Emoji") {
|
||||
// The baseline offset is missing from the Apple Color Emoji UI font data, so add it manually.
|
||||
// This issue doesn't occur with other system emoji fonts.
|
||||
if (!FT_Load_Glyph(p_font_data->face, FT_Get_Char_Index(p_font_data->face, 0x1F92E), FT_LOAD_DEFAULT | FT_LOAD_COLOR)) {
|
||||
if (p_font_data->face->glyph->metrics.horiBearingY == p_font_data->face->glyph->metrics.height) {
|
||||
if (!FT_Load_Glyph(fd->face, FT_Get_Char_Index(fd->face, 0x1F92E), FT_LOAD_DEFAULT | FT_LOAD_COLOR)) {
|
||||
if (fd->face->glyph->metrics.horiBearingY == fd->face->glyph->metrics.height) {
|
||||
p_font_data->baseline_offset = 0.15;
|
||||
}
|
||||
}
|
||||
|
|
@ -1007,15 +1019,15 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
|
|||
#endif
|
||||
|
||||
// Write variations.
|
||||
if (p_font_data->face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) {
|
||||
if (fd->face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) {
|
||||
FT_MM_Var *amaster;
|
||||
|
||||
FT_Get_MM_Var(p_font_data->face, &amaster);
|
||||
FT_Get_MM_Var(fd->face, &amaster);
|
||||
|
||||
Vector<FT_Fixed> coords;
|
||||
coords.resize(amaster->num_axis);
|
||||
|
||||
FT_Get_Var_Design_Coordinates(p_font_data->face, coords.size(), coords.ptrw());
|
||||
FT_Get_Var_Design_Coordinates(fd->face, coords.size(), coords.ptrw());
|
||||
|
||||
for (FT_UInt i = 0; i < amaster->num_axis; i++) {
|
||||
// Reset to default.
|
||||
|
|
@ -1034,7 +1046,7 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
|
|||
}
|
||||
}
|
||||
|
||||
FT_Set_Var_Design_Coordinates(p_font_data->face, coords.size(), coords.ptrw());
|
||||
FT_Set_Var_Design_Coordinates(fd->face, coords.size(), coords.ptrw());
|
||||
FT_Done_MM_Var(ft_library, amaster);
|
||||
}
|
||||
#else
|
||||
|
|
@ -1549,51 +1561,6 @@ bool TextServerFallback::_font_is_modulate_color_glyphs(const RID &p_font_rid) c
|
|||
return fd->modulate_color_glyphs;
|
||||
}
|
||||
|
||||
int64_t TextServerFallback::_font_get_palette_count(const RID &p_font_rid) const {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL_V(fd, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
String TextServerFallback::_font_get_palette_name(const RID &p_font_rid, int64_t p_index) const {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL_V(fd, String());
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
Vector<Color> TextServerFallback::_font_get_palette_colors(const RID &p_font_rid, int64_t p_index) const {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL_V(fd, Vector<Color>());
|
||||
|
||||
return Vector<Color>();
|
||||
}
|
||||
|
||||
void TextServerFallback::_font_set_palette_custom_colors(const RID &p_font_rid, const Vector<Color> &p_colors) {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL(fd);
|
||||
}
|
||||
|
||||
Vector<Color> TextServerFallback::_font_get_palette_custom_colors(const RID &p_font_rid) const {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL_V(fd, Vector<Color>());
|
||||
|
||||
return Vector<Color>();
|
||||
}
|
||||
|
||||
int64_t TextServerFallback::_font_get_used_palette(const RID &p_font_rid) const {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL_V(fd, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TextServerFallback::_font_set_used_palette(const RID &p_font_rid, int64_t p_index) {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL(fd);
|
||||
}
|
||||
|
||||
void TextServerFallback::_font_set_hinting(const RID &p_font_rid, TextServer::Hinting p_hinting) {
|
||||
FontFallback *fd = _get_font_data(p_font_rid);
|
||||
ERR_FAIL_NULL(fd);
|
||||
|
|
@ -2010,7 +1977,7 @@ void TextServerFallback::_font_set_scale(const RID &p_font_rid, int64_t p_size,
|
|||
FontForSizeFallback *ffsd = nullptr;
|
||||
ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (fd->face) {
|
||||
if (ffsd->face) {
|
||||
return; // Do not override scale for dynamic fonts, it's calculated automatically.
|
||||
}
|
||||
#endif
|
||||
|
|
@ -2481,26 +2448,28 @@ RID TextServerFallback::_font_get_glyph_texture_rid(const RID &p_font_rid, const
|
|||
|
||||
ERR_FAIL_COND_V(fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures.size(), RID());
|
||||
|
||||
if (fgl.texture_idx != -1) {
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fgl.from_svg) {
|
||||
// Same as the "fix alpha border" process option when importing SVGs
|
||||
img->fix_alpha_edges();
|
||||
if (RenderingServer::get_singleton() != nullptr) {
|
||||
if (fgl.texture_idx != -1) {
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fgl.from_svg) {
|
||||
// Same as the "fix alpha border" process option when importing SVGs
|
||||
img->fix_alpha_edges();
|
||||
}
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
}
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
return ffsd->textures[fgl.texture_idx].texture->get_rid();
|
||||
}
|
||||
return ffsd->textures[fgl.texture_idx].texture->get_rid();
|
||||
}
|
||||
|
||||
return RID();
|
||||
|
|
@ -2531,26 +2500,28 @@ Size2 TextServerFallback::_font_get_glyph_texture_size(const RID &p_font_rid, co
|
|||
|
||||
ERR_FAIL_COND_V(fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures.size(), Size2());
|
||||
|
||||
if (fgl.texture_idx != -1) {
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fgl.from_svg) {
|
||||
// Same as the "fix alpha border" process option when importing SVGs
|
||||
img->fix_alpha_edges();
|
||||
if (RenderingServer::get_singleton() != nullptr) {
|
||||
if (fgl.texture_idx != -1) {
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fgl.from_svg) {
|
||||
// Same as the "fix alpha border" process option when importing SVGs
|
||||
img->fix_alpha_edges();
|
||||
}
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
}
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
return ffsd->textures[fgl.texture_idx].texture->get_size();
|
||||
}
|
||||
return ffsd->textures[fgl.texture_idx].texture->get_size();
|
||||
}
|
||||
|
||||
return Size2();
|
||||
|
|
@ -2572,17 +2543,17 @@ Dictionary TextServerFallback::_font_get_glyph_contours(const RID &p_font_rid, i
|
|||
|
||||
int32_t index = p_index & 0xffffff; // Remove subpixel shifts.
|
||||
|
||||
int error = FT_Load_Glyph(fd->face, FT_Get_Char_Index(fd->face, index), FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0));
|
||||
int error = FT_Load_Glyph(ffsd->face, FT_Get_Char_Index(ffsd->face, index), FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0));
|
||||
ERR_FAIL_COND_V(error, Dictionary());
|
||||
|
||||
if (fd->embolden != 0.f) {
|
||||
FT_Pos strength = fd->embolden * size.x / 16; // 26.6 fractional units (1 / 64).
|
||||
FT_Outline_Embolden(&fd->face->glyph->outline, strength);
|
||||
FT_Outline_Embolden(&ffsd->face->glyph->outline, strength);
|
||||
}
|
||||
|
||||
if (fd->transform != Transform2D()) {
|
||||
FT_Matrix mat = { FT_Fixed(fd->transform[0][0] * 65536), FT_Fixed(fd->transform[0][1] * 65536), FT_Fixed(fd->transform[1][0] * 65536), FT_Fixed(fd->transform[1][1] * 65536) }; // 16.16 fractional units (1 / 65536).
|
||||
FT_Outline_Transform(&fd->face->glyph->outline, &mat);
|
||||
FT_Outline_Transform(&ffsd->face->glyph->outline, &mat);
|
||||
}
|
||||
|
||||
double scale = (1.0 / 64.0) * ffsd->scale;
|
||||
|
|
@ -2595,13 +2566,13 @@ Dictionary TextServerFallback::_font_get_glyph_contours(const RID &p_font_rid, i
|
|||
scale = scale * Math::round((double)p_size / (double)fd->fixed_size);
|
||||
}
|
||||
}
|
||||
for (short i = 0; i < fd->face->glyph->outline.n_points; i++) {
|
||||
points.push_back(Vector3(fd->face->glyph->outline.points[i].x * scale, -fd->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->face->glyph->outline.tags[i])));
|
||||
for (short i = 0; i < ffsd->face->glyph->outline.n_points; i++) {
|
||||
points.push_back(Vector3(ffsd->face->glyph->outline.points[i].x * scale, -ffsd->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(ffsd->face->glyph->outline.tags[i])));
|
||||
}
|
||||
for (short i = 0; i < fd->face->glyph->outline.n_contours; i++) {
|
||||
contours.push_back(fd->face->glyph->outline.contours[i]);
|
||||
for (short i = 0; i < ffsd->face->glyph->outline.n_contours; i++) {
|
||||
contours.push_back(ffsd->face->glyph->outline.contours[i]);
|
||||
}
|
||||
bool orientation = (FT_Outline_Get_Orientation(&fd->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT);
|
||||
bool orientation = (FT_Outline_Get_Orientation(&ffsd->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT);
|
||||
|
||||
Dictionary out;
|
||||
out["points"] = points;
|
||||
|
|
@ -2692,11 +2663,11 @@ Vector2 TextServerFallback::_font_get_kerning(const RID &p_font_rid, int64_t p_s
|
|||
}
|
||||
} else {
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (fd->face) {
|
||||
if (ffsd->face) {
|
||||
FT_Vector delta;
|
||||
int32_t glyph_a = FT_Get_Char_Index(fd->face, p_glyph_pair.x);
|
||||
int32_t glyph_b = FT_Get_Char_Index(fd->face, p_glyph_pair.y);
|
||||
FT_Get_Kerning(fd->face, glyph_a, glyph_b, FT_KERNING_DEFAULT, &delta);
|
||||
int32_t glyph_a = FT_Get_Char_Index(ffsd->face, p_glyph_pair.x);
|
||||
int32_t glyph_b = FT_Get_Char_Index(ffsd->face, p_glyph_pair.y);
|
||||
FT_Get_Kerning(ffsd->face, glyph_a, glyph_b, FT_KERNING_DEFAULT, &delta);
|
||||
if (fd->msdf) {
|
||||
return Vector2(delta.x, delta.y) * (double)p_size / (double)fd->msdf_source_size;
|
||||
} else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size * 64) {
|
||||
|
|
@ -2739,8 +2710,8 @@ bool TextServerFallback::_font_has_char(const RID &p_font_rid, int64_t p_char) c
|
|||
}
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (fd->face) {
|
||||
return FT_Get_Char_Index(fd->face, p_char) != 0;
|
||||
if (ffsd->face) {
|
||||
return FT_Get_Char_Index(ffsd->face, p_char) != 0;
|
||||
}
|
||||
#endif
|
||||
return ffsd->glyph_map.has((int32_t)p_char);
|
||||
|
|
@ -2760,14 +2731,14 @@ String TextServerFallback::_font_get_supported_chars(const RID &p_font_rid) cons
|
|||
|
||||
String chars;
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (fd->face) {
|
||||
if (ffsd->face) {
|
||||
FT_UInt gindex;
|
||||
FT_ULong charcode = FT_Get_First_Char(fd->face, &gindex);
|
||||
FT_ULong charcode = FT_Get_First_Char(ffsd->face, &gindex);
|
||||
while (gindex != 0) {
|
||||
if (charcode != 0) {
|
||||
chars = chars + String::chr(charcode);
|
||||
}
|
||||
charcode = FT_Get_Next_Char(fd->face, charcode, &gindex);
|
||||
charcode = FT_Get_Next_Char(ffsd->face, charcode, &gindex);
|
||||
}
|
||||
return chars;
|
||||
}
|
||||
|
|
@ -2793,12 +2764,12 @@ PackedInt32Array TextServerFallback::_font_get_supported_glyphs(const RID &p_fon
|
|||
|
||||
PackedInt32Array glyphs;
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (fd->face) {
|
||||
if (at_size && at_size->face) {
|
||||
FT_UInt gindex;
|
||||
FT_ULong charcode = FT_Get_First_Char(fd->face, &gindex);
|
||||
FT_ULong charcode = FT_Get_First_Char(at_size->face, &gindex);
|
||||
while (gindex != 0) {
|
||||
glyphs.push_back(gindex);
|
||||
charcode = FT_Get_Next_Char(fd->face, charcode, &gindex);
|
||||
charcode = FT_Get_Next_Char(at_size->face, charcode, &gindex);
|
||||
}
|
||||
return glyphs;
|
||||
}
|
||||
|
|
@ -2825,7 +2796,7 @@ void TextServerFallback::_font_render_range(const RID &p_font_rid, const Vector2
|
|||
for (int64_t i = p_start; i <= p_end; i++) {
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
int32_t idx = i;
|
||||
if (fd->face) {
|
||||
if (ffsd->face) {
|
||||
FontGlyph fgl;
|
||||
if (fd->msdf) {
|
||||
_ensure_glyph(fd, size, (int32_t)idx, fgl);
|
||||
|
|
@ -2859,7 +2830,7 @@ void TextServerFallback::_font_render_glyph(const RID &p_font_rid, const Vector2
|
|||
ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
int32_t idx = p_index & 0xffffff; // Remove subpixel shifts.
|
||||
if (fd->face) {
|
||||
if (ffsd->face) {
|
||||
FontGlyph fgl;
|
||||
if (fd->msdf) {
|
||||
_ensure_glyph(fd, size, (int32_t)idx, fgl);
|
||||
|
|
@ -2926,7 +2897,7 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
|
|||
bool lcd_aa = false;
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (!fd->msdf && fd->face) {
|
||||
if (!fd->msdf && ffsd->face) {
|
||||
// LCD layout, bits 24, 25, 26
|
||||
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
|
||||
TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
|
||||
|
|
@ -2957,68 +2928,71 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
|
|||
if (fgl.texture_idx != -1) {
|
||||
Color modulate = p_color;
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (!fd->modulate_color_glyphs && fd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
|
||||
if (!fd->modulate_color_glyphs && ffsd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
|
||||
modulate.r = modulate.g = modulate.b = 1.0;
|
||||
}
|
||||
#endif
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fgl.from_svg) {
|
||||
// Same as the "fix alpha border" process option when importing SVGs
|
||||
img->fix_alpha_edges();
|
||||
}
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
}
|
||||
if (fd->msdf) {
|
||||
Point2 cpos = p_pos;
|
||||
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
|
||||
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
|
||||
ffsd->textures[fgl.texture_idx].texture->draw_msdf_rect_region(p_canvas, Rect2(cpos, csize), fgl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
|
||||
} else {
|
||||
Point2 cpos = p_pos;
|
||||
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
|
||||
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.125;
|
||||
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.25;
|
||||
}
|
||||
if (scale == 1.0) {
|
||||
cpos.y = Math::floor(cpos.y);
|
||||
cpos.x = Math::floor(cpos.x);
|
||||
}
|
||||
Vector2 gpos = fgl.rect.position;
|
||||
Size2 csize = fgl.rect.size;
|
||||
if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE) {
|
||||
if (size.x != p_size * 64) {
|
||||
if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) {
|
||||
double gl_scale = (double)p_size / (double)fd->fixed_size;
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
} else {
|
||||
double gl_scale = Math::round((double)p_size / (double)fd->fixed_size);
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
}
|
||||
if (RenderingServer::get_singleton() != nullptr) {
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fgl.from_svg) {
|
||||
// Same as the "fix alpha border" process option when importing SVGs
|
||||
img->fix_alpha_edges();
|
||||
}
|
||||
} else {
|
||||
gpos /= oversampling_factor;
|
||||
csize /= oversampling_factor;
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
}
|
||||
cpos += gpos;
|
||||
if (lcd_aa) {
|
||||
ffsd->textures[fgl.texture_idx].texture->draw_lcd_rect_region(p_canvas, Rect2(cpos, csize), fgl.uv_rect, modulate);
|
||||
RID texture = ffsd->textures[fgl.texture_idx].texture->get_rid();
|
||||
if (fd->msdf) {
|
||||
Point2 cpos = p_pos;
|
||||
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
|
||||
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
|
||||
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
|
||||
} else {
|
||||
ffsd->textures[fgl.texture_idx].texture->draw_rect_region(p_canvas, Rect2(cpos, csize), fgl.uv_rect, modulate, false, false);
|
||||
Point2 cpos = p_pos;
|
||||
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
|
||||
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.125;
|
||||
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.25;
|
||||
}
|
||||
if (scale == 1.0) {
|
||||
cpos.y = Math::floor(cpos.y);
|
||||
cpos.x = Math::floor(cpos.x);
|
||||
}
|
||||
Vector2 gpos = fgl.rect.position;
|
||||
Size2 csize = fgl.rect.size;
|
||||
if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE) {
|
||||
if (size.x != p_size * 64) {
|
||||
if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) {
|
||||
double gl_scale = (double)p_size / (double)fd->fixed_size;
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
} else {
|
||||
double gl_scale = Math::round((double)p_size / (double)fd->fixed_size);
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gpos /= oversampling_factor;
|
||||
csize /= oversampling_factor;
|
||||
}
|
||||
cpos += gpos;
|
||||
if (lcd_aa) {
|
||||
RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate);
|
||||
} else {
|
||||
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3069,7 +3043,7 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R
|
|||
bool lcd_aa = false;
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (!fd->msdf && fd->face) {
|
||||
if (!fd->msdf && ffsd->face) {
|
||||
// LCD layout, bits 24, 25, 26
|
||||
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
|
||||
TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
|
||||
|
|
@ -3100,64 +3074,67 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R
|
|||
if (fgl.texture_idx != -1) {
|
||||
Color modulate = p_color;
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (fd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
|
||||
if (ffsd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
|
||||
modulate.r = modulate.g = modulate.b = 1.0;
|
||||
}
|
||||
#endif
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
}
|
||||
if (fd->msdf) {
|
||||
Point2 cpos = p_pos;
|
||||
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
|
||||
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
|
||||
ffsd->textures[fgl.texture_idx].texture->draw_msdf_rect_region(p_canvas, Rect2(cpos, csize), fgl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
|
||||
} else {
|
||||
Point2 cpos = p_pos;
|
||||
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
|
||||
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.125;
|
||||
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.25;
|
||||
}
|
||||
if (scale == 1.0) {
|
||||
cpos.y = Math::floor(cpos.y);
|
||||
cpos.x = Math::floor(cpos.x);
|
||||
}
|
||||
Vector2 gpos = fgl.rect.position;
|
||||
Size2 csize = fgl.rect.size;
|
||||
if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE) {
|
||||
if (size.x != p_size * 64) {
|
||||
if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) {
|
||||
double gl_scale = (double)p_size / (double)fd->fixed_size;
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
} else {
|
||||
double gl_scale = Math::round((double)p_size / (double)fd->fixed_size);
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
}
|
||||
if (RenderingServer::get_singleton() != nullptr) {
|
||||
if (ffsd->textures[fgl.texture_idx].dirty) {
|
||||
ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
|
||||
Ref<Image> img = tex.image;
|
||||
if (fd->mipmaps && !img->has_mipmaps()) {
|
||||
img = tex.image->duplicate();
|
||||
img->generate_mipmaps();
|
||||
}
|
||||
} else {
|
||||
gpos /= oversampling_factor;
|
||||
csize /= oversampling_factor;
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture = ImageTexture::create_from_image(img);
|
||||
} else {
|
||||
tex.texture->update(img);
|
||||
}
|
||||
tex.dirty = false;
|
||||
}
|
||||
cpos += gpos;
|
||||
if (lcd_aa) {
|
||||
ffsd->textures[fgl.texture_idx].texture->draw_lcd_rect_region(p_canvas, Rect2(cpos, csize), fgl.uv_rect, modulate);
|
||||
RID texture = ffsd->textures[fgl.texture_idx].texture->get_rid();
|
||||
if (fd->msdf) {
|
||||
Point2 cpos = p_pos;
|
||||
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
|
||||
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
|
||||
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
|
||||
} else {
|
||||
ffsd->textures[fgl.texture_idx].texture->draw_rect_region(p_canvas, Rect2(cpos, csize), fgl.uv_rect, modulate, false, false);
|
||||
Point2 cpos = p_pos;
|
||||
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
|
||||
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.125;
|
||||
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) {
|
||||
cpos.x = cpos.x + 0.25;
|
||||
}
|
||||
if (scale == 1.0) {
|
||||
cpos.y = Math::floor(cpos.y);
|
||||
cpos.x = Math::floor(cpos.x);
|
||||
}
|
||||
Vector2 gpos = fgl.rect.position;
|
||||
Size2 csize = fgl.rect.size;
|
||||
if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE) {
|
||||
if (size.x != p_size * 64) {
|
||||
if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) {
|
||||
double gl_scale = (double)p_size / (double)fd->fixed_size;
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
} else {
|
||||
double gl_scale = Math::round((double)p_size / (double)fd->fixed_size);
|
||||
gpos *= gl_scale;
|
||||
csize *= gl_scale;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gpos /= oversampling_factor;
|
||||
csize /= oversampling_factor;
|
||||
}
|
||||
cpos += gpos;
|
||||
if (lcd_aa) {
|
||||
RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate);
|
||||
} else {
|
||||
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4482,7 +4459,12 @@ RID TextServerFallback::_find_sys_font_for_text(const RID &p_fdef, const String
|
|||
|
||||
String locale = (p_language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : p_language;
|
||||
PackedStringArray fallback_font_name = OS::get_singleton()->get_system_font_path_for_text(font_name, p_text, locale, p_script_code, font_weight, font_stretch, font_style & TextServer::FONT_ITALIC);
|
||||
#ifdef GDEXTENSION
|
||||
for (int fb = 0; fb < fallback_font_name.size(); fb++) {
|
||||
const String &E = fallback_font_name[fb];
|
||||
#elif defined(GODOT_MODULE)
|
||||
for (const String &E : fallback_font_name) {
|
||||
#endif
|
||||
SystemFontKey key = SystemFontKey(E, font_style & TextServer::FONT_ITALIC, font_weight, font_stretch, p_fdef, this);
|
||||
if (system_fonts.has(key)) {
|
||||
const SystemFontCache &sysf_cache = system_fonts[key];
|
||||
|
|
@ -4595,7 +4577,7 @@ RID TextServerFallback::_find_sys_font_for_text(const RID &p_fdef, const String
|
|||
Vector2i size = _get_size(fd, 16);
|
||||
FontForSizeFallback *ffsd = nullptr;
|
||||
if (_ensure_cache_for_size(fd, size, ffsd)) {
|
||||
if (ffsd && (FT_HAS_COLOR(fd->face) || !FT_IS_SCALABLE(fd->face))) {
|
||||
if (ffsd && (FT_HAS_COLOR(ffsd->face) || !FT_IS_SCALABLE(ffsd->face))) {
|
||||
fb_use_msdf = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -5238,7 +5220,11 @@ PackedInt32Array TextServerFallback::_shaped_text_get_character_breaks(const RID
|
|||
if (size > 0) {
|
||||
ret.resize(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
#ifdef GDEXTENSION
|
||||
ret[i] = i + 1 + sd->start;
|
||||
#else
|
||||
ret.write[i] = i + 1 + sd->start;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,52 @@
|
|||
/* BiDi, shaping and advanced font features support. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/extension/ext_wrappers.gen.h"
|
||||
#ifdef GDEXTENSION
|
||||
// Headers for building as GDExtension plug-in.
|
||||
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/core/ext_wrappers.gen.inc>
|
||||
#include <godot_cpp/core/mutex_lock.hpp>
|
||||
|
||||
#include <godot_cpp/variant/array.hpp>
|
||||
#include <godot_cpp/variant/dictionary.hpp>
|
||||
#include <godot_cpp/variant/packed_int32_array.hpp>
|
||||
#include <godot_cpp/variant/packed_string_array.hpp>
|
||||
#include <godot_cpp/variant/packed_vector2_array.hpp>
|
||||
#include <godot_cpp/variant/rect2.hpp>
|
||||
#include <godot_cpp/variant/rid.hpp>
|
||||
#include <godot_cpp/variant/string.hpp>
|
||||
#include <godot_cpp/variant/typed_array.hpp>
|
||||
#include <godot_cpp/variant/vector2.hpp>
|
||||
#include <godot_cpp/variant/vector2i.hpp>
|
||||
|
||||
#include <godot_cpp/classes/text_server.hpp>
|
||||
#include <godot_cpp/classes/text_server_extension.hpp>
|
||||
#include <godot_cpp/classes/text_server_manager.hpp>
|
||||
|
||||
#include <godot_cpp/classes/caret_info.hpp>
|
||||
#include <godot_cpp/classes/global_constants_binds.hpp>
|
||||
#include <godot_cpp/classes/glyph.hpp>
|
||||
#include <godot_cpp/classes/image.hpp>
|
||||
#include <godot_cpp/classes/image_texture.hpp>
|
||||
#include <godot_cpp/classes/ref.hpp>
|
||||
#include <godot_cpp/classes/worker_thread_pool.hpp>
|
||||
|
||||
#include <godot_cpp/templates/hash_map.hpp>
|
||||
#include <godot_cpp/templates/hash_set.hpp>
|
||||
#include <godot_cpp/templates/rid_owner.hpp>
|
||||
#include <godot_cpp/templates/safe_refcount.hpp>
|
||||
#include <godot_cpp/templates/vector.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
#elif defined(GODOT_MODULE)
|
||||
// Headers for building as built-in module.
|
||||
|
||||
#include "core/extension/ext_wrappers.gen.inc"
|
||||
#include "core/object/worker_thread_pool.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "core/templates/safe_refcount.h"
|
||||
|
|
@ -44,6 +89,8 @@
|
|||
|
||||
#include "modules/modules_enabled.gen.h" // For freetype, msdfgen, svg.
|
||||
|
||||
#endif
|
||||
|
||||
// Thirdparty headers.
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
|
|
@ -54,7 +101,6 @@
|
|||
#include FT_ADVANCES_H
|
||||
#include FT_MULTIPLE_MASTERS_H
|
||||
#include FT_BBOX_H
|
||||
#include FT_SIZES_H
|
||||
#include FT_MODULE_H
|
||||
#include FT_CONFIG_OPTIONS_H
|
||||
#if !defined(FT_CONFIG_OPTION_USE_BROTLI) && !defined(_MSC_VER)
|
||||
|
|
@ -193,13 +239,14 @@ class TextServerFallback : public TextServerExtension {
|
|||
HashMap<Vector2i, Vector2> kerning_map;
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
FT_Size fsize = nullptr;
|
||||
FT_Face face = nullptr;
|
||||
FT_StreamRec stream;
|
||||
#endif
|
||||
|
||||
~FontForSizeFallback() {
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (fsize != nullptr) {
|
||||
FT_Done_Size(fsize);
|
||||
if (face != nullptr) {
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -263,21 +310,11 @@ class TextServerFallback : public TextServerExtension {
|
|||
size_t data_size;
|
||||
int face_index = 0;
|
||||
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
FT_Face face = nullptr;
|
||||
FT_StreamRec stream;
|
||||
#endif
|
||||
|
||||
~FontFallback() {
|
||||
for (const KeyValue<Vector2i, FontForSizeFallback *> &E : cache) {
|
||||
memdelete(E.value);
|
||||
}
|
||||
cache.clear();
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
if (face != nullptr) {
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -649,14 +686,6 @@ public:
|
|||
MODBIND2(font_set_modulate_color_glyphs, const RID &, bool);
|
||||
MODBIND1RC(bool, font_is_modulate_color_glyphs, const RID &);
|
||||
|
||||
MODBIND1RC(int64_t, font_get_palette_count, const RID &);
|
||||
MODBIND2RC(String, font_get_palette_name, const RID &, int64_t);
|
||||
MODBIND2RC(Vector<Color>, font_get_palette_colors, const RID &, int64_t);
|
||||
MODBIND2(font_set_palette_custom_colors, const RID &, const Vector<Color> &);
|
||||
MODBIND1RC(Vector<Color>, font_get_palette_custom_colors, const RID &);
|
||||
MODBIND1RC(int64_t, font_get_used_palette, const RID &);
|
||||
MODBIND2(font_set_used_palette, const RID &, int64_t);
|
||||
|
||||
MODBIND2(font_set_subpixel_positioning, const RID &, SubpixelPositioning);
|
||||
MODBIND1RC(SubpixelPositioning, font_get_subpixel_positioning, const RID &);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,14 +30,29 @@
|
|||
|
||||
#include "thorvg_svg_in_ot.h"
|
||||
|
||||
#ifdef GDEXTENSION
|
||||
// Headers for building as GDExtension plug-in.
|
||||
|
||||
#include <godot_cpp/classes/xml_parser.hpp>
|
||||
#include <godot_cpp/core/mutex_lock.hpp>
|
||||
#include <godot_cpp/godot.hpp>
|
||||
#include <godot_cpp/templates/vector.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
#elif defined(GODOT_MODULE)
|
||||
// Headers for building as built-in module.
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/io/xml_parser.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/typedefs.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h" // For svg, freetype.
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_SVG_ENABLED
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
|
|
@ -45,6 +60,8 @@
|
|||
#include <freetype/otsvg.h>
|
||||
#include <ft2build.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
FT_Error tvg_svg_in_ot_init(FT_Pointer *p_state) {
|
||||
*p_state = memnew(TVG_State);
|
||||
|
||||
|
|
@ -163,7 +180,11 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
|
|||
if (!is_in_defs && parser->has_attribute("id")) {
|
||||
const String &gl_name = parser->get_named_attribute_value("id");
|
||||
if (gl_name.begins_with("glyph")) {
|
||||
#ifdef GDEXTENSION
|
||||
int dot_pos = gl_name.find(".");
|
||||
#else
|
||||
int dot_pos = gl_name.find_char('.');
|
||||
#endif // GDEXTENSION
|
||||
int64_t gl_idx = gl_name.substr(5, (dot_pos > 0) ? dot_pos - 5 : -1).to_int();
|
||||
|
||||
TVG_NodeCache node_cache = TVG_NodeCache();
|
||||
|
|
@ -201,12 +222,11 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
|
|||
cache.embox_y = embox_y;
|
||||
}
|
||||
|
||||
tvg::Picture *picture = tvg::Picture::gen();
|
||||
std::unique_ptr<tvg::Picture> picture = tvg::Picture::gen();
|
||||
gl_state.xml_code = xml_body.utf8();
|
||||
|
||||
tvg::Result result = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", nullptr, false);
|
||||
tvg::Result result = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false);
|
||||
if (result != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (glyph metrics).");
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +237,6 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
|
|||
|
||||
result = picture->size(embox_x * aspect_x, embox_y * aspect_y);
|
||||
if (result != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to resize SVG document.");
|
||||
}
|
||||
|
||||
|
|
@ -239,13 +258,11 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
|
|||
|
||||
result = picture->size(embox_x * aspect_x * x_svg_to_out, embox_y * aspect_y * y_svg_to_out);
|
||||
if (result != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to resize SVG document.");
|
||||
}
|
||||
|
||||
result = picture->transform(gl_state.m);
|
||||
if (result != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to apply transform to SVG document.");
|
||||
}
|
||||
|
||||
|
|
@ -254,8 +271,6 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
|
|||
gl_state.x = (double(p_slot->metrics.horiAdvance) / 64.0 - gl_state.w) / 2.0;
|
||||
gl_state.y = -Math::ceil(gl_state.h * yoff);
|
||||
|
||||
tvg::Paint::rel(picture);
|
||||
|
||||
gl_state.ready = true;
|
||||
}
|
||||
|
||||
|
|
@ -310,30 +325,26 @@ FT_Error tvg_svg_in_ot_render(FT_GlyphSlot p_slot, FT_Pointer *p_state) {
|
|||
GL_State &gl_state = state->glyph_map[p_slot->glyph_index];
|
||||
ERR_FAIL_COND_V_MSG(!gl_state.ready, FT_Err_Invalid_SVG_Document, "SVG glyph not ready.");
|
||||
|
||||
tvg::Picture *picture = tvg::Picture::gen();
|
||||
tvg::Result res = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", nullptr, false);
|
||||
std::unique_ptr<tvg::Picture> picture = tvg::Picture::gen();
|
||||
tvg::Result res = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false);
|
||||
if (res != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (glyph rendering).");
|
||||
}
|
||||
res = picture->size(gl_state.w, gl_state.h);
|
||||
if (res != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to resize SVG document.");
|
||||
}
|
||||
res = picture->transform(gl_state.m);
|
||||
if (res != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to apply transform to SVG document.");
|
||||
}
|
||||
|
||||
std::unique_ptr<tvg::SwCanvas> sw_canvas(tvg::SwCanvas::gen());
|
||||
res = sw_canvas->target((uint32_t *)p_slot->bitmap.buffer, (int)p_slot->bitmap.width, (int)p_slot->bitmap.width, (int)p_slot->bitmap.rows, tvg::ColorSpace::ARGB8888S);
|
||||
std::unique_ptr<tvg::SwCanvas> sw_canvas = tvg::SwCanvas::gen();
|
||||
res = sw_canvas->target((uint32_t *)p_slot->bitmap.buffer, (int)p_slot->bitmap.width, (int)p_slot->bitmap.width, (int)p_slot->bitmap.rows, tvg::SwCanvas::ARGB8888S);
|
||||
if (res != tvg::Result::Success) {
|
||||
tvg::Paint::rel(picture);
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_Outline, "Failed to create SVG canvas.");
|
||||
}
|
||||
res = sw_canvas->add(picture);
|
||||
res = sw_canvas->push(std::move(picture));
|
||||
if (res != tvg::Result::Success) {
|
||||
ERR_FAIL_V_MSG(FT_Err_Invalid_Outline, "Failed to set SVG canvas source.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,25 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifdef GDEXTENSION
|
||||
// Headers for building as GDExtension plug-in.
|
||||
|
||||
#include <godot_cpp/core/mutex_lock.hpp>
|
||||
#include <godot_cpp/godot.hpp>
|
||||
#include <godot_cpp/templates/hash_map.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
#elif defined(GODOT_MODULE)
|
||||
// Headers for building as built-in module.
|
||||
|
||||
#include "core/os/mutex.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
#include "core/typedefs.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h" // For svg, freetype.
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_SVG_ENABLED
|
||||
#ifdef MODULE_FREETYPE_ENABLED
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue