* added debug output * refactored documaster
@@ -1,14 +1,14 @@ | |||
lib/ | |||
bin/ | |||
debug/ | |||
inc/utsTextSuiteVersion.inc | |||
*.so | |||
*.lps | |||
*.exe | |||
*.res | |||
*.ico | |||
*.dbg | |||
*.dll | |||
*.zip | |||
*.heaptrc | |||
*.heaptrace | |||
lib/ | |||
bin/ | |||
debug/ | |||
inc/utsTextSuiteVersion.inc | |||
*.so | |||
*.lps | |||
*.exe | |||
*.res | |||
*.ico | |||
*.dbg | |||
*.dll | |||
*.zip | |||
*.heaptrc | |||
*.heaptrace |
@@ -1,9 +1,9 @@ | |||
[submodule "src/TextSuite"] | |||
path = src/TextSuite | |||
url = b3rgmann@git.bergmann89.de:opengl/TextSuite.git | |||
[submodule "src/OpenGLCore"] | |||
path = src/OpenGLCore | |||
url = b3rgmann@git.bergmann89.de:opengl/OpenGLCore.git | |||
[submodule "src/Utils"] | |||
path = src/Utils | |||
url = b3rgmann@git.bergmann89.de:freepascal/utils.git | |||
[submodule "src/TextSuite"] | |||
path = src/TextSuite | |||
url = b3rgmann@git.bergmann89.de:opengl/TextSuite.git | |||
[submodule "src/OpenGLCore"] | |||
path = src/OpenGLCore | |||
url = b3rgmann@git.bergmann89.de:opengl/OpenGLCore.git | |||
[submodule "src/Utils"] | |||
path = src/Utils | |||
url = b3rgmann@git.bergmann89.de:freepascal/utils.git |
@@ -0,0 +1,17 @@ | |||
# Overview | |||
libTextSuite is a dynamic library that encapsulate the [TextSuite](https://git.bergmann89.de/opengl/TextSuite) project to be able to use it on different platforms and programming languages. Out of the box the following platforms and languages are supported. | |||
- __supported platforms__ | |||
- i386-win32 | |||
- x64_64-win64 | |||
- i386-linux | |||
- x86_64-linux | |||
- __supported languages__ | |||
- C | |||
- C++ | |||
- C# | |||
- FPC | |||
- (Delphi) | |||
A detailed [Documentation](./doc/docu.md) is shipped with every copy of libTextSuite. |
@@ -12,6 +12,7 @@ DOCU_DIR="$SCRIPTDIR/doc" | |||
INC_MAJOR=false | |||
INC_MINOR=false | |||
INC_BUGFIX=false | |||
ALLZIPDIR="$SCRIPTDIR/TextSuite-all" | |||
if [ -z "$FIRST_VERSION" ]; then | |||
FIRST_VERSION="0.0.0.0" | |||
@@ -133,7 +134,7 @@ printf "const Version = 'v$NEWVERSION $HASH';" > inc/utsTextSuiteVersion.inc | |||
function BuildConfig() | |||
{ | |||
CONFIG=$1 | |||
POSTFIX=$2 | |||
TARGET=$2 | |||
FILEEXT=$3 | |||
DBGEXT=".dbg" | |||
@@ -144,36 +145,47 @@ function BuildConfig() | |||
cleaupAndExit 1 | |||
fi | |||
ZIPDIR="bin/$POSTFIX" | |||
BINDIR="$ZIPDIR" | |||
ZIPPATH="$SCRIPTDIR/libTextSuite-$POSTFIX.zip" | |||
BINDIR="$SCRIPTDIR/bin" | |||
ZIPDIR="$SCRIPTDIR/TextSuite-$TARGET" | |||
ZIPPATH="$SCRIPTDIR/TextSuite-$TARGET.zip" | |||
if [ -n "$TAGNAME" ]; then | |||
mkdir -p "$SCRIPTDIR/$TAGNAME/" | |||
ZIPPATH="$SCRIPTDIR/$TAGNAME/libTextSuite-$POSTFIX.zip" | |||
ZIPPATH="$SCRIPTDIR/$TAGNAME/TextSuite-$TARGET.zip" | |||
fi | |||
BINNAME="libTextSuite-$POSTFIX$FILEEXT" | |||
DBGNAME="libTextSuite-$POSTFIX$DBGEXT" | |||
TARGETDIR="$BINDIR/$TARGET" | |||
BINNAME="$TARGETDIR/libtextsuite$FILEEXT" | |||
DBGNAME="$TARGETDIR/libtextsuite$DBGEXT" | |||
if [ ! -f $BINNAME ]; then | |||
echo "file not found: $EXENAME" | |||
echo "file not found: $BINNAME" | |||
cleaupAndExit 2 | |||
fi | |||
# extract debug infos | |||
cp "$BINNAME" "$DBGNAME" || { log "unable to copy binary to *.dbg"; cleaupAndExit 3; } | |||
objcopy --only-keep-debug "$DBGNAME" || { log "unable to strip $DBGNAME"; cleaupAndExit 3; } | |||
objcopy --strip-debug --strip-unneeded "$BINNAME" || { log "unable to copy binary to $BINNAME"; cleaupAndExit 3; } | |||
objcopy --add-gnu-debuglink "$DBGNAME" "$BINNAME" || { log "unable to create debug link"; cleaupAndExit 3; } | |||
if [ ! -f $DBGNAME ]; then | |||
echo "file not found: $DBGNAME" | |||
cleaupAndExit 2 | |||
fi | |||
mkdir -p $BINDIR | |||
mv "$BINNAME" "$BINDIR/" || { log "unable to copy linked binary"; cleaupAndExit 3; } | |||
mv "$DBGNAME" "$BINDIR/" || { log "unable to copy linked debug infos"; cleaupAndExit 3; } | |||
# use this to copy data folder instead of data archive: cp -R --preserve=links data $BINDIR || { log "unable to copy data folder"; cleaupAndExit 4; } | |||
cp -r "$HEADER_DIR" "$BINDIR" || { log "unable to copy header files"; cleaupAndExit 4; } | |||
cp -r "$DOCU_DIR" "$BINDIR/docu" || { log "unable to copy documentation files"; cleaupAndExit 5; } | |||
# copy header and docu | |||
mkdir -p "$ZIPDIR/bin" | |||
cp -r "$TARGETDIR" "$ZIPDIR/bin" || { log "unable to copy binaries"; cleaupAndExit 3; } | |||
cp -r "$HEADER_DIR" "$ZIPDIR" || { log "unable to copy header files"; cleaupAndExit 4; } | |||
cp -r "$DOCU_DIR" "$ZIPDIR/docu" || { log "unable to copy documentation files"; cleaupAndExit 5; } | |||
pushd $ZIPDIR | |||
rm -rf $ZIPPATH | |||
zip -r $ZIPPATH ./* || { log "unable to create zip archive"; cleaupAndExit 6; } | |||
pushd "$ZIPDIR" | |||
rm -rf "$ZIPPATH" | |||
zip -r "$ZIPPATH" "." || { log "unable to create zip archive"; cleaupAndExit 6; } | |||
popd | |||
mkdir -p "$ALLZIPDIR" | |||
echo "mv $ZIPDIR/* $ALLZIPDIR/" | |||
cp -rf $ZIPDIR/* $ALLZIPDIR/ || { log "unable to copy binaries to all directory"; cleaupAndExit 3; } | |||
rm -rf "$ZIPDIR" | |||
} | |||
while [[ $# -gt 0 ]]; do | |||
@@ -218,5 +230,17 @@ BuildConfig "Win64Release" "x86_64-win64" ".dll" | |||
BuildConfig "Linux32Release" "i386-linux" ".so" | |||
BuildConfig "Linux64Release" "x86_64-linux" ".so" | |||
ALLZIPPATH="$SCRIPTDIR/TextSuite-all.zip" | |||
if [ -n "$TAGNAME" ]; then | |||
mkdir -p "$SCRIPTDIR/$TAGNAME/" | |||
ALLZIPPATH="$SCRIPTDIR/$TAGNAME/TextSuite-all.zip" | |||
fi | |||
pushd "$ALLZIPDIR" | |||
rm -rf "$ALLZIPPATH" | |||
zip -r "$ALLZIPPATH" "." || { log "unable to create zip archive"; cleaupAndExit 6; } | |||
popd | |||
rm -rf "$ALLZIPDIR" | |||
cleaupAndExit 0 | |||
@@ -1,12 +1,12 @@ | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
gcc -DWIN32 example.c main-mingw.c -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
gcc -DLINUX -o example main-gnuc.c example.c -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
gcc -DWIN32 example.c main-mingw.c -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
gcc -DLINUX -o example main-gnuc.c example.c -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
rm -rf example.exe |
@@ -1,179 +1,179 @@ | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.h" | |||
#else | |||
# include "..\..\libTextSuite.h" | |||
#endif | |||
#if _WIN64 | |||
# define LIB_NAME "..\\..\\..\\libTextSuite-x86_64-win64.dll" | |||
#elif _WIN32 | |||
# define LIB_NAME "..\\..\\..\\libTextSuite-i386-win32.dll" | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
# define LIB_NAME "../../../libTextSuite-x86_64-linux.so" | |||
#elif __linux__ && (__i386 || _X86_) | |||
# define LIB_NAME "../../../libTextSuite-i386-linux.so" | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreator ltsFontCreatorFreeType | |||
#else | |||
# define FontCreator ltsFontCreatorGDI | |||
#endif | |||
lts_context_handle_t context; | |||
lts_font_creator_handle_t creator; | |||
lts_renderer_handle_t renderer; | |||
lts_font_handle_t font; | |||
lts_post_processor_handle_t pp; | |||
lts_post_processor_handle_t ppFillPattern; | |||
lts_post_processor_handle_t ppFillColor; | |||
lts_post_processor_handle_t ppBorder; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts_wchar_t CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts_wchar_t CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
void WINAPI execute_post_proc(lts_char_handle_t charHandle, lts_image_handle_t imageHandle) | |||
{ | |||
lts_post_processor_execute(ppFillPattern, charHandle, imageHandle); | |||
lts_post_processor_execute(ppFillColor, charHandle, imageHandle); | |||
lts_post_processor_execute(ppBorder, charHandle, imageHandle); | |||
} | |||
bool exampleInit() | |||
{ | |||
if (lts_initialize(LIB_NAME) != ltsErrNone) | |||
{ | |||
showMessage("unable to initialize library"); | |||
return false; | |||
} | |||
context = lts_context_create(); | |||
if (!context) | |||
{ | |||
showMessage("unable to create text suite context"); | |||
return false; | |||
} | |||
renderer = lts_renderer_create(context, ltsRendererOpenGL, ltsFormatRGBA8); | |||
if (!renderer) | |||
{ | |||
showMessage("unable to create text suite renderer"); | |||
return false; | |||
} | |||
creator = lts_font_creator_create(context, FontCreator); | |||
if (!creator) | |||
{ | |||
showMessage("unable to create text suite creator"); | |||
return false; | |||
} | |||
lts_post_processor_custom_data_t ppData; | |||
ppData.args = NULL; | |||
ppData.execute = &execute_post_proc; | |||
pp = lts_post_processor_custom_create(context, &ppData); | |||
if (!pp) | |||
{ | |||
showMessage("unable to create custom post processor"); | |||
return false; | |||
} | |||
lts_image_handle_t img = lts_image_create(context); | |||
lts_image_create_empty(img, ltsFormatAlpha8, 4, 4); | |||
void* imgData = lts_image_get_data(img); | |||
if (img) memcpy(imgData, &PATTER_DATA[0], 16); | |||
ppFillPattern = lts_post_processor_fill_pattern_create(context, img, true, ltsPosition(0, 0), LTS_IMAGE_MODES_MODULATE_ALL, LTS_COLOR_CHANNELS_RGBA); | |||
lts_post_processor_add_chars(ppFillPattern, ltsUsageInclude, &CHAR_RANGE_LOREM[0]); | |||
ppFillColor = lts_post_processor_fill_color_create(context, ltsColor4f(0.0, 0.0, 0.5, 1.0), LTS_IMAGE_MODES_REPLACE_ALL, LTS_COLOR_CHANNELS_RGB); | |||
lts_post_processor_add_chars(ppFillColor, ltsUsageExclude, &CHAR_RANGE_E[0]); | |||
ppBorder = lts_post_processor_border_create(context, 3.0, 0.5, ltsColor4f(0.0, 0.5, 0.0, 1.0), true); | |||
lts_post_processor_add_chars(ppBorder, ltsUsageInclude, &CHAR_RANGE_E[0]); | |||
font = lts_font_creator_get_font_by_file(creator, "../Prototype.ttf", 40, 0, ltsAANormal); | |||
if (!font) | |||
{ | |||
showMessage("unable to create text suite font"); | |||
return false; | |||
} | |||
if (lts_font_set_post_processor(font, pp) != ltsErrNone) | |||
{ | |||
showMessage("unable to set post processor"); | |||
return false; | |||
} | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
const lts_color4f_t color = { 1.0, 1.0, 1.0, 1.0 }; | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
lts_block_flags_t flags = 0; | |||
FLAGS_SET(flags, ltsBlockFlagWordWrap); | |||
lts_text_block_handle_t textBlock = lts_renderer_begin_block(renderer, 10, 10, width-20, height-20, flags); | |||
if (!textBlock) | |||
{ | |||
showMessage(lts_get_last_error_msg()); | |||
return false; | |||
} | |||
if (lts_text_block_set_horz_align(textBlock, ltsHorzAlignJustify) != ltsErrNone) | |||
{ | |||
showMessage("unable to set horizontal alignment"); | |||
return false; | |||
} | |||
if (lts_text_block_set_font(textBlock, font) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_set_color(textBlock, color) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_text_out_a(textBlock, TEST_TEXT) != ltsErrNone) | |||
{ | |||
showMessage("unable to print text"); | |||
return false; | |||
} | |||
if (lts_renderer_end_block(renderer, textBlock) != ltsErrNone) | |||
{ | |||
showMessage("unable to finish text block"); | |||
return false; | |||
} | |||
//lts_text_block_destroy(textBlock); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
lts_font_destroy(font); | |||
lts_post_processor_destroy(ppBorder); | |||
lts_post_processor_destroy(ppFillColor); | |||
lts_post_processor_destroy(ppFillPattern); | |||
lts_post_processor_destroy(pp); | |||
lts_font_creator_destroy(creator); | |||
lts_renderer_destroy(creator); | |||
lts_context_destroy(context); | |||
lts_finalize(); | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.h" | |||
#else | |||
# include "..\..\libTextSuite.h" | |||
#endif | |||
#if _WIN64 | |||
# define LIB_NAME "..\\..\\..\\bin\\x86_64-win64\\libtextsuite.dll" | |||
#elif _WIN32 | |||
# define LIB_NAME "..\\..\\..\\bin\\i386-win32\\libtextsuite.dll" | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
# define LIB_NAME "../../../bin/x86_64-linux/libtextsuite.so" | |||
#elif __linux__ && (__i386 || _X86_) | |||
# define LIB_NAME "../../../bin/i386-linux/libtextsuite.so" | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreator ltsFontCreatorFreeType | |||
#else | |||
# define FontCreator ltsFontCreatorGDI | |||
#endif | |||
lts_context_handle_t context; | |||
lts_font_creator_handle_t creator; | |||
lts_renderer_handle_t renderer; | |||
lts_font_handle_t font; | |||
lts_post_processor_handle_t pp; | |||
lts_post_processor_handle_t ppFillPattern; | |||
lts_post_processor_handle_t ppFillColor; | |||
lts_post_processor_handle_t ppBorder; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts_wchar_t CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts_wchar_t CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
void WINAPI execute_post_proc(lts_char_handle_t charHandle, lts_image_handle_t imageHandle) | |||
{ | |||
lts_post_processor_execute(ppFillPattern, charHandle, imageHandle); | |||
lts_post_processor_execute(ppFillColor, charHandle, imageHandle); | |||
lts_post_processor_execute(ppBorder, charHandle, imageHandle); | |||
} | |||
bool exampleInit() | |||
{ | |||
if (lts_initialize(LIB_NAME) != ltsErrNone) | |||
{ | |||
showMessage("unable to initialize library"); | |||
return false; | |||
} | |||
context = lts_context_create(); | |||
if (!context) | |||
{ | |||
showMessage("unable to create text suite context"); | |||
return false; | |||
} | |||
renderer = lts_renderer_create(context, ltsRendererOpenGL, ltsFormatRGBA8); | |||
if (!renderer) | |||
{ | |||
showMessage("unable to create text suite renderer"); | |||
return false; | |||
} | |||
creator = lts_font_creator_create(context, FontCreator); | |||
if (!creator) | |||
{ | |||
showMessage("unable to create text suite creator"); | |||
return false; | |||
} | |||
lts_post_processor_custom_data_t ppData; | |||
ppData.args = NULL; | |||
ppData.execute = &execute_post_proc; | |||
pp = lts_post_processor_custom_create(context, &ppData); | |||
if (!pp) | |||
{ | |||
showMessage("unable to create custom post processor"); | |||
return false; | |||
} | |||
lts_image_handle_t img = lts_image_create(context); | |||
lts_image_create_empty(img, ltsFormatAlpha8, 4, 4); | |||
void* imgData = lts_image_get_data(img); | |||
if (img) memcpy(imgData, &PATTER_DATA[0], 16); | |||
ppFillPattern = lts_post_processor_fill_pattern_create(context, img, true, ltsPosition(0, 0), LTS_IMAGE_MODES_MODULATE_ALL, LTS_COLOR_CHANNELS_RGBA); | |||
lts_post_processor_add_chars(ppFillPattern, ltsUsageInclude, &CHAR_RANGE_LOREM[0]); | |||
ppFillColor = lts_post_processor_fill_color_create(context, ltsColor4f(0.0, 0.0, 0.5, 1.0), LTS_IMAGE_MODES_REPLACE_ALL, LTS_COLOR_CHANNELS_RGB); | |||
lts_post_processor_add_chars(ppFillColor, ltsUsageExclude, &CHAR_RANGE_E[0]); | |||
ppBorder = lts_post_processor_border_create(context, 3.0, 0.5, ltsColor4f(0.0, 0.5, 0.0, 1.0), true); | |||
lts_post_processor_add_chars(ppBorder, ltsUsageInclude, &CHAR_RANGE_E[0]); | |||
font = lts_font_creator_get_font_by_file(creator, "../Prototype.ttf", 40, 0, ltsAANormal); | |||
if (!font) | |||
{ | |||
showMessage("unable to create text suite font"); | |||
return false; | |||
} | |||
if (lts_font_set_post_processor(font, pp) != ltsErrNone) | |||
{ | |||
showMessage("unable to set post processor"); | |||
return false; | |||
} | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
const lts_color4f_t color = { 1.0, 1.0, 1.0, 1.0 }; | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
lts_block_flags_t flags = 0; | |||
FLAGS_SET(flags, ltsBlockFlagWordWrap); | |||
lts_text_block_handle_t textBlock = lts_renderer_begin_block(renderer, 10, 10, width-20, height-20, flags); | |||
if (!textBlock) | |||
{ | |||
showMessage(lts_get_last_error_msg()); | |||
return false; | |||
} | |||
if (lts_text_block_set_horz_align(textBlock, ltsHorzAlignJustify) != ltsErrNone) | |||
{ | |||
showMessage("unable to set horizontal alignment"); | |||
return false; | |||
} | |||
if (lts_text_block_set_font(textBlock, font) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_set_color(textBlock, color) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_text_out_a(textBlock, TEST_TEXT) != ltsErrNone) | |||
{ | |||
showMessage("unable to print text"); | |||
return false; | |||
} | |||
if (lts_renderer_end_block(renderer, textBlock) != ltsErrNone) | |||
{ | |||
showMessage("unable to finish text block"); | |||
return false; | |||
} | |||
//lts_text_block_destroy(textBlock); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
lts_font_destroy(font); | |||
lts_post_processor_destroy(ppBorder); | |||
lts_post_processor_destroy(ppFillColor); | |||
lts_post_processor_destroy(ppFillPattern); | |||
lts_post_processor_destroy(pp); | |||
lts_font_creator_destroy(creator); | |||
lts_renderer_destroy(creator); | |||
lts_context_destroy(context); | |||
lts_finalize(); | |||
} |
@@ -1,10 +1,10 @@ | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#endif /* EXAMPLE_H */ |
@@ -1,16 +1,16 @@ | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#endif /* HELPER_H */ |
@@ -1,57 +1,57 @@ | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
} |
@@ -1,159 +1,159 @@ | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
} |
@@ -1,12 +1,12 @@ | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
g++ -std=c++11 -DWIN32 -static-libgcc -static-libstdc++ main-mingw.cpp example.cpp -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
g++ -std=c++11 -DLINUX -o example main-gnuc.cpp example.cpp -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
g++ -std=c++11 -DWIN32 -static-libgcc -static-libstdc++ main-mingw.cpp example.cpp -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
g++ -g -std=c++11 -DLINUX -o example main-gnuc.cpp example.cpp -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
rm -rf example.exe |
@@ -1,127 +1,127 @@ | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include <string.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.hpp" | |||
#else | |||
# include "..\..\libTextSuite.hpp" | |||
#endif | |||
#if _WIN64 | |||
static const std::string LibName("..\\..\\..\\libTextSuite-x86_64-win64.dll"); | |||
#elif _WIN32 | |||
static const std::string LibName("..\\..\\..\\libTextSuite-i386-win32.dll"); | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
static const std::string LibName("../../../libTextSuite-x86_64-linux.so"); | |||
#elif __linux__ && (__i386 || _X86_) | |||
static const std::string LibName("../../../libTextSuite-i386-linux.so"); | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreatorExample FontCreatorFreeType | |||
#else | |||
# define FontCreatorExample FontCreatorGDI | |||
#endif | |||
typedef std::unique_ptr<lts::PostProcessor> PostProcessorPtrU; | |||
std::shared_ptr<lts::Library> library; | |||
std::shared_ptr<lts::Context> context; | |||
std::shared_ptr<lts::FontCreator> creator; | |||
std::shared_ptr<lts::Renderer> renderer; | |||
std::shared_ptr<lts::Image> pattern; | |||
std::shared_ptr<lts::Font> font; | |||
std::shared_ptr<lts::PostProcessorList<PostProcessorPtrU>> ppList; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts::WideChar CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts::WideChar CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
bool exampleInit() | |||
{ | |||
library.reset(new lts::Library(LibName)); | |||
context.reset(new lts::Context(*library)); | |||
creator.reset(new lts::FontCreatorExample(*context)); | |||
renderer.reset(new lts::RendererOpenGL(*context, lts::Format::RGBA8)); | |||
ppList.reset(new lts::PostProcessorList<PostProcessorPtrU>(*context)); | |||
pattern.reset(new lts::Image(*context)); | |||
pattern->createEmpty(lts::Format::Alpha8, 4, 4); | |||
memcpy(pattern->getData(), &PATTER_DATA[0], 16); | |||
PostProcessorPtrU ppFillPattern(new lts::PostProcessorFillPattern( | |||
*context, | |||
*pattern, | |||
lts::Position{0, 0}, | |||
lts::ImageModeModulateAll, | |||
lts::ColorChannelsRGBA)); | |||
ppFillPattern->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_LOREM[0]); | |||
ppList->push_back(std::move(ppFillPattern)); | |||
PostProcessorPtrU ppFillColor(new lts::PostProcessorFillColor( | |||
*context, | |||
lts::Color4f{ 0.0, 0.0, 0.5, 1.0 }, | |||
lts::ImageModeReplaceAll, | |||
lts::ColorChannelsRGB)); | |||
ppFillColor->addChars(lts::CharRangeUsage::Exclude, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppFillColor)); | |||
PostProcessorPtrU ppBorder(new lts::PostProcessorBorder( | |||
*context, | |||
3.0, | |||
0.5, | |||
lts::Color4f{ 0.0, 0.5, 0.0, 1.0 }, | |||
true)); | |||
ppBorder->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppBorder)); | |||
font = creator->getFontByFile( | |||
"../Prototype.ttf", | |||
40, | |||
lts::FontStyles(), | |||
lts::AntiAliasing::Normal); | |||
font->setPostProcessor(ppList.get()); | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
auto textBlock = renderer->beginBlock(10, 10, width-20, height-20, lts::BlockFlags({ lts::BlockFlag::WordWrap })); | |||
textBlock->setHorzAlign(lts::HorzAlign::Justify); | |||
textBlock->setFont(font.get()); | |||
textBlock->setColor(lts::Color4f{ 1.0, 1.0, 1.0, 1.0 }); | |||
textBlock->textOutA(TEST_TEXT); | |||
renderer->endBlock(std::move(textBlock)); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
font.reset(); | |||
ppList.reset(); | |||
pattern.reset(); | |||
renderer.reset(); | |||
creator.reset(); | |||
context.reset(); | |||
library.reset(); | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include <string.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.hpp" | |||
#else | |||
# include "..\..\libTextSuite.hpp" | |||
#endif | |||
#if _WIN64 | |||
static const std::string LibName("..\\..\\..\\bin\\x86_64-win64\\libtextsuite.dll"); | |||
#elif _WIN32 | |||
static const std::string LibName("..\\..\\..\\bin\\i386-win32\\libtextsuite.dll"); | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
static const std::string LibName("../../../bin/x86_64-linux/libtextsuite.so"); | |||
#elif __linux__ && (__i386 || _X86_) | |||
static const std::string LibName("../../../bin/i386-linux/libtextsuite.so"); | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreatorExample FontCreatorFreeType | |||
#else | |||
# define FontCreatorExample FontCreatorGDI | |||
#endif | |||
typedef std::unique_ptr<lts::PostProcessor> PostProcessorPtrU; | |||
std::shared_ptr<lts::Library> library; | |||
std::shared_ptr<lts::Context> context; | |||
std::shared_ptr<lts::FontCreator> creator; | |||
std::shared_ptr<lts::Renderer> renderer; | |||
std::shared_ptr<lts::Image> pattern; | |||
std::shared_ptr<lts::Font> font; | |||
std::shared_ptr<lts::PostProcessorList<PostProcessorPtrU>> ppList; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts::WideChar CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts::WideChar CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
bool exampleInit() | |||
{ | |||
library.reset(new lts::Library(LibName)); | |||
context.reset(new lts::Context(*library)); | |||
creator.reset(new lts::FontCreatorExample(*context)); | |||
renderer.reset(new lts::RendererOpenGL(*context, lts::Format::RGBA8)); | |||
ppList.reset(new lts::PostProcessorList<PostProcessorPtrU>(*context)); | |||
pattern.reset(new lts::Image(*context)); | |||
pattern->createEmpty(lts::Format::Alpha8, 4, 4); | |||
memcpy(pattern->getData(), &PATTER_DATA[0], 16); | |||
PostProcessorPtrU ppFillPattern(new lts::PostProcessorFillPattern( | |||
*context, | |||
*pattern, | |||
lts::Position{0, 0}, | |||
lts::ImageModeModulateAll, | |||
lts::ColorChannelsRGBA)); | |||
ppFillPattern->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_LOREM[0]); | |||
ppList->push_back(std::move(ppFillPattern)); | |||
PostProcessorPtrU ppFillColor(new lts::PostProcessorFillColor( | |||
*context, | |||
lts::Color4f{ 0.0, 0.0, 0.5, 1.0 }, | |||
lts::ImageModeReplaceAll, | |||
lts::ColorChannelsRGB)); | |||
ppFillColor->addChars(lts::CharRangeUsage::Exclude, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppFillColor)); | |||
PostProcessorPtrU ppBorder(new lts::PostProcessorBorder( | |||
*context, | |||
3.0, | |||
0.5, | |||
lts::Color4f{ 0.0, 0.5, 0.0, 1.0 }, | |||
true)); | |||
ppBorder->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppBorder)); | |||
font = creator->getFontByFile( | |||
"../Prototype.ttf", | |||
40, | |||
lts::FontStyles(), | |||
lts::AntiAliasing::Normal); | |||
font->setPostProcessor(ppList.get()); | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
auto textBlock = renderer->beginBlock(10, 10, width-20, height-20, lts::BlockFlags({ lts::BlockFlag::WordWrap })); | |||
textBlock->setHorzAlign(lts::HorzAlign::Justify); | |||
textBlock->setFont(font.get()); | |||
textBlock->setColor(lts::Color4f{ 1.0, 1.0, 1.0, 1.0 }); | |||
textBlock->textOutA(TEST_TEXT); | |||
renderer->endBlock(std::move(textBlock)); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
font.reset(); | |||
ppList.reset(); | |||
pattern.reset(); | |||
renderer.reset(); | |||
creator.reset(); | |||
context.reset(); | |||
library.reset(); | |||
} |
@@ -1,10 +1,10 @@ | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#endif /* EXAMPLE_H */ |
@@ -1,16 +1,16 @@ | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#endif /* HELPER_H */ |
@@ -1,74 +1,74 @@ | |||
#include <iostream> | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include <exception> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
try | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
glutDestroyWindow(windowId); | |||
} | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
try | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
#include <iostream> | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include <exception> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
try | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
glutDestroyWindow(windowId); | |||
} | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
try | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
} |
@@ -1,182 +1,182 @@ | |||
#include <iostream> | |||
#include <exception> | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include <stdio.h> | |||
#include "helper.h" | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
bool canRender = false; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
try | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
canRender = true; | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
if (!canRender) | |||
break; | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
MessageBox(hwnd, ex.what(), "Exception", MB_OK); | |||
SysShutdown(); | |||
} | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
try | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
#include <iostream> | |||
#include <exception> | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include <stdio.h> | |||
#include "helper.h" | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
bool canRender = false; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
try | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
canRender = true; | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
if (!canRender) | |||
break; | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
MessageBox(hwnd, ex.what(), "Exception", MB_OK); | |||
SysShutdown(); | |||
} | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
try | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
Thumbs.db | |||
*.obj | |||
*.user | |||
*.aps | |||
*.pch | |||
*.vspscc | |||
*.ncb | |||
*.suo | |||
*.sln.docstates | |||
*.bak | |||
*.cache | |||
*.ilk | |||
*.log | |||
*.lib | |||
*.sbr | |||
*.vssscc | |||
obj/ | |||
bin/ | |||
.vs/ |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<configuration> | |||
<startup> | |||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> | |||
</startup> | |||
</configuration> |
@@ -0,0 +1,9 @@ | |||
<Application x:Class="libTextSuiteExample.App" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:local="clr-namespace:libTextSuiteExample" | |||
StartupUri="MainWindow.xaml"> | |||
<Application.Resources> | |||
</Application.Resources> | |||
</Application> |
@@ -0,0 +1,13 @@ | |||
using System; | |||
using System.IO; | |||
using System.Reflection; | |||
using System.Windows; | |||
namespace libTextSuiteExample | |||
{ | |||
/// <summary> | |||
/// Interaktionslogik für "App.xaml" | |||
/// </summary> | |||
public partial class App : Application | |||
{ } | |||
} |
@@ -0,0 +1,20 @@ | |||
<Window x:Class="libTextSuiteExample.MainWindow" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:sharpGL="clr-namespace:SharpGL.WPF;assembly=SharpGL.WPF" | |||
xmlns:local="clr-namespace:libTextSuiteExample" | |||
mc:Ignorable="d" | |||
Title="libTextSuite exmple" Height="480" Width="640" | |||
Closing="Window_Closing"> | |||
<Grid> | |||
<sharpGL:OpenGLControl | |||
x:Name="oglControl" | |||
OpenGLDraw="oglControl_OpenGLDraw" | |||
OpenGLInitialized="oglControl_OpenGLInitialized" | |||
Resized="oglControl_Resized" | |||
RenderContextType="FBO" | |||
/> | |||
</Grid> | |||
</Window> |
@@ -0,0 +1,168 @@ | |||
using SharpGL; | |||
using SharpGL.SceneGraph; | |||
using System; | |||
using System.IO; | |||
using System.Reflection; | |||
using System.Runtime.InteropServices; | |||
using System.Windows; | |||
namespace libTextSuiteExample | |||
{ | |||
public partial class MainWindow : Window | |||
{ | |||
private static readonly string TEST_TEXT = @"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
private lts.Context _context; | |||
private lts.FontCreator _fontCreator; | |||
private lts.Renderer _renderer; | |||
private lts.Font _font; | |||
private lts.Image _pattern; | |||
private lts.PostProcessorList _ppList; | |||
private static readonly string LibTextSuiteDllName = "libtextsuite.dll"; | |||
[DllImport("kernel32.dll")] | |||
private static extern IntPtr LoadLibrary(string dllToLoad); | |||
public MainWindow() | |||
{ | |||
InitializeComponent(); | |||
// load libtextsuite depending on architecture | |||
string exeDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); | |||
string archDir = Environment.Is64BitProcess ? "x64" : "x86"; | |||
string dllPath = Path.Combine(exeDir, "resources", archDir, LibTextSuiteDllName); | |||
var handle = LoadLibrary(dllPath); | |||
if (handle == IntPtr.Zero) | |||
{ | |||
MessageBox.Show("Unable to load libtextsuite.dll", "Error", MessageBoxButton.OK, MessageBoxImage.Error); | |||
Application.Current.Shutdown(); | |||
} | |||
} | |||
private void oglControl_OpenGLInitialized(object sender, OpenGLEventArgs args) | |||
{ | |||
var gl = args.OpenGL; | |||
gl.Disable(OpenGL.GL_DEPTH_TEST); | |||
gl.Disable(OpenGL.GLU_CULLING); | |||
gl.Enable(OpenGL.GL_BLEND); | |||
gl.ClearColor(1.0f, 1.0f, 1.0f, 1.0f); | |||
gl.MakeCurrent(); | |||
string exeDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); | |||
string fontPath = Path.Combine(exeDir, "resources", "Prototype.ttf"); | |||
_context = new lts.Context(); | |||
_renderer = new lts.RendererOpenGl(_context, lts.Format.RGBA8); | |||
_fontCreator = new lts.FontCreatorGdi(_context); | |||
_font = _fontCreator.GetFontByFile(fontPath, 40, lts.FontStyles.Empty, lts.AntiAliasing.Normal); | |||
_ppList = new lts.PostProcessorList(_context); | |||
_font.PostProcessor = _ppList; | |||
_pattern = new lts.Image(_context); | |||
_pattern.CreateEmpty(lts.Format.Alpha8, 4, 4); | |||
_pattern.Data = new byte[] { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
lts.PostProcessor pp = new lts.PostProcessorFillPattern( | |||
_context, | |||
_pattern, | |||
new lts.Position() { x = 0, y = 0 }, | |||
lts.Constants.ImageModeModulateAll, | |||
lts.Constants.ColorChannelsRGBA); | |||
pp.AddChars(lts.CharRangeUsage.Include, "Lorem"); | |||
_ppList.Add(pp); | |||
pp = new lts.PostProcessorFillColor( | |||
_context, | |||
new lts.Color() { R = 0.0f, G = 0.0f, B = 0.5f, A = 1.0f }, | |||
lts.Constants.ImageModeReplaceAll, | |||
lts.Constants.ColorChannelsRGB); | |||
pp.AddChars(lts.CharRangeUsage.Exclude, "e"); | |||
_ppList.Add(pp); | |||
pp = new lts.PostProcessorBorder( | |||
_context, | |||
3.0f, | |||
0.5f, | |||
new lts.Color() { R = 0.0f, G = 0.5f, B = 0.0f, A = 1.0f }, | |||
true); | |||
pp.AddChars(lts.CharRangeUsage.Include, "e"); | |||
_ppList.Add(pp); | |||
} | |||
private void oglControl_OpenGLDraw(object sender, OpenGLEventArgs args) | |||
{ | |||
var gl = args.OpenGL; | |||
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); | |||
gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA); | |||
using (var textBlock = _renderer.BeginBlock(10, 10, (Int32)oglControl.ActualWidth - 20, (Int32)oglControl.ActualHeight - 20, lts.BlockFlags.WordWrap)) | |||
{ | |||
textBlock.HorzAlign = lts.HorzAlign.Justify; | |||
textBlock.Font = _font; | |||
textBlock.Color = new lts.Color() { R = 1.0f, G = 1.0f, B = 1.0f, A = 1.0f }; | |||
textBlock.TextOut(TEST_TEXT); | |||
_renderer.EndBlock(textBlock); | |||
} | |||
gl.Flush(); | |||
} | |||
private void oglControl_Resized(object sender, OpenGLEventArgs args) | |||
{ | |||
var gl = args.OpenGL; | |||
gl.MatrixMode(OpenGL.GL_PROJECTION); | |||
gl.LoadIdentity(); | |||
gl.Ortho(0, gl.RenderContextProvider.Width, gl.RenderContextProvider.Height, 0, 10, -10); | |||
gl.MatrixMode(OpenGL.GL_MODELVIEW); | |||
gl.LoadIdentity(); | |||
} | |||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) | |||
{ | |||
if (_ppList != null) | |||
{ | |||
foreach (var pp in _ppList) | |||
pp.Dispose(); | |||
_ppList.Dispose(); | |||
_ppList.Clear(); | |||
_ppList = null; | |||
} | |||
if (_pattern != null) | |||
{ | |||
_pattern.Dispose(); | |||
_pattern = null; | |||
} | |||
if (_font != null) | |||
{ | |||
_font.Dispose(); | |||
_font = null; | |||
} | |||
if (_fontCreator != null) | |||
{ | |||
_fontCreator.Dispose(); | |||
_fontCreator = null; | |||
} | |||
if (_renderer != null) | |||
{ | |||
_renderer.Dispose(); | |||
_renderer = null; | |||
} | |||
if (_context != null) | |||
{ | |||
_context.Dispose(); | |||
_context = null; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,55 @@ | |||
using System.Reflection; | |||
using System.Resources; | |||
using System.Runtime.CompilerServices; | |||
using System.Runtime.InteropServices; | |||
using System.Windows; | |||
// Allgemeine Informationen über eine Assembly werden über die folgenden | |||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, | |||
// die einer Assembly zugeordnet sind. | |||
[assembly: AssemblyTitle("libTextSuiteExample")] | |||
[assembly: AssemblyDescription("")] | |||
[assembly: AssemblyConfiguration("")] | |||
[assembly: AssemblyCompany("")] | |||
[assembly: AssemblyProduct("libTextSuiteExample")] | |||
[assembly: AssemblyCopyright("Copyright © 2017")] | |||
[assembly: AssemblyTrademark("")] | |||
[assembly: AssemblyCulture("")] | |||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly | |||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von | |||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. | |||
[assembly: ComVisible(false)] | |||
//Um mit dem Erstellen lokalisierbarer Anwendungen zu beginnen, legen Sie | |||
//<UICulture>ImCodeVerwendeteKultur</UICulture> in der .csproj-Datei | |||
//in einer <PropertyGroup> fest. Wenn Sie in den Quelldateien beispielsweise Deutsch | |||
//(Deutschland) verwenden, legen Sie <UICulture> auf \"de-DE\" fest. Heben Sie dann die Auskommentierung | |||
//des nachstehenden NeutralResourceLanguage-Attributs auf. Aktualisieren Sie "en-US" in der nachstehenden Zeile, | |||
//sodass es mit der UICulture-Einstellung in der Projektdatei übereinstimmt. | |||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | |||
[assembly: ThemeInfo( | |||
ResourceDictionaryLocation.None, //Speicherort der designspezifischen Ressourcenwörterbücher | |||
//(wird verwendet, wenn eine Ressource auf der Seite nicht gefunden wird, | |||
// oder in den Anwendungsressourcen-Wörterbüchern nicht gefunden werden kann.) | |||
ResourceDictionaryLocation.SourceAssembly //Speicherort des generischen Ressourcenwörterbuchs | |||
//(wird verwendet, wenn eine Ressource auf der Seite nicht gefunden wird, | |||
// designspezifischen Ressourcenwörterbuch nicht gefunden werden kann.) | |||
)] | |||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: | |||
// | |||
// Hauptversion | |||
// Nebenversion | |||
// Buildnummer | |||
// Revision | |||
// | |||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, | |||
// übernehmen, indem Sie "*" eingeben: | |||
// [assembly: AssemblyVersion("1.0.*")] | |||
[assembly: AssemblyVersion("1.0.0.0")] | |||
[assembly: AssemblyFileVersion("1.0.0.0")] |
@@ -0,0 +1,63 @@ | |||
//------------------------------------------------------------------------------ | |||
// <auto-generated> | |||
// Dieser Code wurde von einem Tool generiert. | |||
// Laufzeitversion:4.0.30319.42000 | |||
// | |||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn | |||
// der Code erneut generiert wird. | |||
// </auto-generated> | |||
//------------------------------------------------------------------------------ | |||
namespace libTextSuiteExample.Properties { | |||
using System; | |||
/// <summary> | |||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. | |||
/// </summary> | |||
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert | |||
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. | |||
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen | |||
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. | |||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] | |||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] | |||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] | |||
internal class Resources { | |||
private static global::System.Resources.ResourceManager resourceMan; | |||
private static global::System.Globalization.CultureInfo resourceCulture; | |||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] | |||
internal Resources() { | |||
} | |||
/// <summary> | |||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. | |||
/// </summary> | |||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] | |||
internal static global::System.Resources.ResourceManager ResourceManager { | |||
get { | |||
if (object.ReferenceEquals(resourceMan, null)) { | |||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("libTextSuiteExample.Properties.Resources", typeof(Resources).Assembly); | |||
resourceMan = temp; | |||
} | |||
return resourceMan; | |||
} | |||
} | |||
/// <summary> | |||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle | |||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. | |||
/// </summary> | |||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] | |||
internal static global::System.Globalization.CultureInfo Culture { | |||
get { | |||
return resourceCulture; | |||
} | |||
set { | |||
resourceCulture = value; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,117 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<root> | |||
<!-- | |||
Microsoft ResX Schema | |||
Version 2.0 | |||
The primary goals of this format is to allow a simple XML format | |||
that is mostly human readable. The generation and parsing of the | |||
various data types are done through the TypeConverter classes | |||
associated with the data types. | |||
Example: | |||
... ado.net/XML headers & schema ... | |||
<resheader name="resmimetype">text/microsoft-resx</resheader> | |||
<resheader name="version">2.0</resheader> | |||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> | |||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> | |||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> | |||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> | |||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> | |||
<value>[base64 mime encoded serialized .NET Framework object]</value> | |||
</data> | |||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> | |||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> | |||
<comment>This is a comment</comment> | |||
</data> | |||
There are any number of "resheader" rows that contain simple | |||
name/value pairs. | |||
Each data row contains a name, and value. The row also contains a | |||
type or mimetype. Type corresponds to a .NET class that support | |||
text/value conversion through the TypeConverter architecture. | |||
Classes that don't support this are serialized and stored with the | |||
mimetype set. | |||
The mimetype is used for serialized objects, and tells the | |||
ResXResourceReader how to depersist the object. This is currently not | |||
extensible. For a given mimetype the value must be set accordingly: | |||
Note - application/x-microsoft.net.object.binary.base64 is the format | |||
that the ResXResourceWriter will generate, however the reader can | |||
read any of the formats listed below. | |||
mimetype: application/x-microsoft.net.object.binary.base64 | |||
value : The object must be serialized with | |||
: System.Serialization.Formatters.Binary.BinaryFormatter | |||
: and then encoded with base64 encoding. | |||
mimetype: application/x-microsoft.net.object.soap.base64 | |||
value : The object must be serialized with | |||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter | |||
: and then encoded with base64 encoding. | |||
mimetype: application/x-microsoft.net.object.bytearray.base64 | |||
value : The object must be serialized into a byte array | |||
: using a System.ComponentModel.TypeConverter | |||
: and then encoded with base64 encoding. | |||
--> | |||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | |||
<xsd:element name="root" msdata:IsDataSet="true"> | |||
<xsd:complexType> | |||
<xsd:choice maxOccurs="unbounded"> | |||
<xsd:element name="metadata"> | |||
<xsd:complexType> | |||
<xsd:sequence> | |||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | |||
</xsd:sequence> | |||
<xsd:attribute name="name" type="xsd:string" /> | |||
<xsd:attribute name="type" type="xsd:string" /> | |||
<xsd:attribute name="mimetype" type="xsd:string" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
<xsd:element name="assembly"> | |||
<xsd:complexType> | |||
<xsd:attribute name="alias" type="xsd:string" /> | |||
<xsd:attribute name="name" type="xsd:string" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
<xsd:element name="data"> | |||
<xsd:complexType> | |||
<xsd:sequence> | |||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | |||
</xsd:sequence> | |||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> | |||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | |||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
<xsd:element name="resheader"> | |||
<xsd:complexType> | |||
<xsd:sequence> | |||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |||
</xsd:sequence> | |||
<xsd:attribute name="name" type="xsd:string" use="required" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
</xsd:choice> | |||
</xsd:complexType> | |||
</xsd:element> | |||
</xsd:schema> | |||
<resheader name="resmimetype"> | |||
<value>text/microsoft-resx</value> | |||
</resheader> | |||
<resheader name="version"> | |||
<value>2.0</value> | |||
</resheader> | |||
<resheader name="reader"> | |||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
</resheader> | |||
<resheader name="writer"> | |||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
</resheader> | |||
</root> |
@@ -0,0 +1,26 @@ | |||
//------------------------------------------------------------------------------ | |||
// <auto-generated> | |||
// Dieser Code wurde von einem Tool generiert. | |||
// Laufzeitversion:4.0.30319.42000 | |||
// | |||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn | |||
// der Code erneut generiert wird. | |||
// </auto-generated> | |||
//------------------------------------------------------------------------------ | |||
namespace libTextSuiteExample.Properties { | |||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] | |||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] | |||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { | |||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); | |||
public static Settings Default { | |||
get { | |||
return defaultInstance; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
<?xml version='1.0' encoding='utf-8'?> | |||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)"> | |||
<Profiles> | |||
<Profile Name="(Default)" /> | |||
</Profiles> | |||
<Settings /> | |||
</SettingsFile> |
@@ -0,0 +1,129 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |||
<PropertyGroup> | |||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||
<ProjectGuid>{09D8B134-1C53-43C0-8AB1-B1553F561483}</ProjectGuid> | |||
<OutputType>WinExe</OutputType> | |||
<RootNamespace>libTextSuiteExample</RootNamespace> | |||
<AssemblyName>libTextSuiteExample</AssemblyName> | |||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |||
<FileAlignment>512</FileAlignment> | |||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | |||
<WarningLevel>4</WarningLevel> | |||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | |||
<TargetFrameworkProfile> | |||
</TargetFrameworkProfile> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
<PlatformTarget>AnyCPU</PlatformTarget> | |||
<DebugSymbols>true</DebugSymbols> | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>bin\Debug\</OutputPath> | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
<Prefer32Bit>false</Prefer32Bit> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
<PlatformTarget>AnyCPU</PlatformTarget> | |||
<DebugType>pdbonly</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>bin\Release\</OutputPath> | |||
<DefineConstants>TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<Prefer32Bit>false</Prefer32Bit> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Reference Include="SharpGL"> | |||
<HintPath>lib\SharpGL.dll</HintPath> | |||
</Reference> | |||
<Reference Include="SharpGL.SceneGraph"> | |||
<HintPath>lib\SharpGL.SceneGraph.dll</HintPath> | |||
</Reference> | |||
<Reference Include="SharpGL.WPF"> | |||
<HintPath>lib\SharpGL.WPF.dll</HintPath> | |||
</Reference> | |||
<Reference Include="System" /> | |||
<Reference Include="System.Data" /> | |||
<Reference Include="System.Design" /> | |||
<Reference Include="System.Xml" /> | |||
<Reference Include="Microsoft.CSharp" /> | |||
<Reference Include="System.Core" /> | |||
<Reference Include="System.Xml.Linq" /> | |||
<Reference Include="System.Data.DataSetExtensions" /> | |||
<Reference Include="System.Xaml"> | |||
<RequiredTargetFramework>4.0</RequiredTargetFramework> | |||
</Reference> | |||
<Reference Include="WindowsBase" /> | |||
<Reference Include="PresentationCore" /> | |||
<Reference Include="PresentationFramework" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ApplicationDefinition Include="App.xaml"> | |||
<Generator>MSBuild:Compile</Generator> | |||
<SubType>Designer</SubType> | |||
</ApplicationDefinition> | |||
<Page Include="MainWindow.xaml"> | |||
<Generator>MSBuild:Compile</Generator> | |||
<SubType>Designer</SubType> | |||
</Page> | |||
<Compile Include="..\..\libTextSuite.cs"> | |||
<Link>libTextSuite.cs</Link> | |||
</Compile> | |||
<Compile Include="App.xaml.cs"> | |||
<DependentUpon>App.xaml</DependentUpon> | |||
<SubType>Code</SubType> | |||
</Compile> | |||
<Compile Include="MainWindow.xaml.cs"> | |||
<DependentUpon>MainWindow.xaml</DependentUpon> | |||
<SubType>Code</SubType> | |||
</Compile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="Properties\AssemblyInfo.cs"> | |||
<SubType>Code</SubType> | |||
</Compile> | |||
<Compile Include="Properties\Resources.Designer.cs"> | |||
<AutoGen>True</AutoGen> | |||
<DesignTime>True</DesignTime> | |||
<DependentUpon>Resources.resx</DependentUpon> | |||
</Compile> | |||
<Compile Include="Properties\Settings.Designer.cs"> | |||
<AutoGen>True</AutoGen> | |||
<DependentUpon>Settings.settings</DependentUpon> | |||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | |||
</Compile> | |||
<EmbeddedResource Include="Properties\Resources.resx"> | |||
<Generator>ResXFileCodeGenerator</Generator> | |||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | |||
</EmbeddedResource> | |||
<Content Include="..\Prototype.ttf"> | |||
<Link>resources\Prototype.ttf</Link> | |||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |||
</Content> | |||
<None Include="Properties\Settings.settings"> | |||
<Generator>SettingsSingleFileGenerator</Generator> | |||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | |||
</None> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="App.config" /> | |||
</ItemGroup> | |||
<ItemGroup /> | |||
<ItemGroup> | |||
<Content Include="..\..\..\bin\i386-win32\libtextsuite.dll"> | |||
<Link>resources\x86\libtextsuite.dll</Link> | |||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |||
</Content> | |||
<Content Include="..\..\..\bin\x86_64-win64\libtextsuite.dll"> | |||
<Link>resources\x64\libtextsuite.dll</Link> | |||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |||
</Content> | |||
</ItemGroup> | |||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
</Project> |
@@ -0,0 +1,22 @@ | |||
| |||
Microsoft Visual Studio Solution File, Format Version 12.00 | |||
# Visual Studio 15 | |||
VisualStudioVersion = 15.0.26403.3 | |||
MinimumVisualStudioVersion = 10.0.40219.1 | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libTextSuiteExample", "libTextSuiteExample.csproj", "{09D8B134-1C53-43C0-8AB1-B1553F561483}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
Release|Any CPU = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{09D8B134-1C53-43C0-8AB1-B1553F561483}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{09D8B134-1C53-43C0-8AB1-B1553F561483}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{09D8B134-1C53-43C0-8AB1-B1553F561483}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{09D8B134-1C53-43C0-8AB1-B1553F561483}.Release|Any CPU.Build.0 = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
EndGlobalSection | |||
EndGlobal |
@@ -1,92 +1,92 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<CONFIG> | |||
<ProjectOptions> | |||
<Version Value="10"/> | |||
<PathDelim Value="\"/> | |||
<General> | |||
<SessionStorage Value="InProjectDir"/> | |||
<MainUnit Value="0"/> | |||
<Title Value="example"/> | |||
<ResourceType Value="res"/> | |||
<UseXPManifest Value="True"/> | |||
</General> | |||
<i18n> | |||
<EnableI18N LFM="False"/> | |||
</i18n> | |||
<BuildModes Count="1"> | |||
<Item1 Name="Default" Default="True"/> | |||
</BuildModes> | |||
<PublishOptions> | |||
<Version Value="2"/> | |||
</PublishOptions> | |||
<RunParams> | |||
<local> | |||
<FormatVersion Value="1"/> | |||
</local> | |||
</RunParams> | |||
<RequiredPackages Count="1"> | |||
<Item1> | |||
<PackageName Value="LCL"/> | |||
</Item1> | |||
</RequiredPackages> | |||
<Units Count="3"> | |||
<Unit0> | |||
<Filename Value="example.lpr"/> | |||
<IsPartOfProject Value="True"/> | |||
</Unit0> | |||
<Unit1> | |||
<Filename Value="uMainForm.pas"/> | |||
<IsPartOfProject Value="True"/> | |||
<ComponentName Value="MainForm"/> | |||
<HasResources Value="True"/> | |||
<ResourceBaseClass Value="Form"/> | |||
</Unit1> | |||
<Unit2> | |||
<Filename Value="..\..\ulibTextSuite.pas"/> | |||
<IsPartOfProject Value="True"/> | |||
</Unit2> | |||
</Units> | |||
</ProjectOptions> | |||
<CompilerOptions> | |||
<Version Value="11"/> | |||
<PathDelim Value="\"/> | |||
<Target> | |||
<Filename Value="example"/> | |||
</Target> | |||
<SearchPaths> | |||
<IncludeFiles Value="$(ProjOutDir)"/> | |||
<OtherUnitFiles Value="..\.."/> | |||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> | |||
</SearchPaths> | |||
<Linking> | |||
<Debugging> | |||
<UseHeaptrc Value="True"/> | |||
<UseExternalDbgSyms Value="True"/> | |||
</Debugging> | |||
<Options> | |||
<Win32> | |||
<GraphicApplication Value="True"/> | |||
</Win32> | |||
</Options> | |||
</Linking> | |||
<Other> | |||
<CompilerMessages> | |||
<IgnoredMessages idx5024="True"/> | |||
</CompilerMessages> | |||
<CustomOptions Value="-dDUMP_HEAPTRACE"/> | |||
</Other> | |||
</CompilerOptions> | |||
<Debugging> | |||
<Exceptions Count="3"> | |||
<Item1> | |||
<Name Value="EAbort"/> | |||
</Item1> | |||
<Item2> | |||
<Name Value="ECodetoolError"/> | |||
</Item2> | |||
<Item3> | |||
<Name Value="EFOpenError"/> | |||
</Item3> | |||
</Exceptions> | |||
</Debugging> | |||
</CONFIG> | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<CONFIG> | |||
<ProjectOptions> | |||
<Version Value="10"/> | |||
<PathDelim Value="\"/> | |||
<General> | |||
<SessionStorage Value="InProjectDir"/> | |||
<MainUnit Value="0"/> | |||
<Title Value="example"/> | |||
<ResourceType Value="res"/> | |||
<UseXPManifest Value="True"/> | |||
</General> | |||
<i18n> | |||
<EnableI18N LFM="False"/> | |||
</i18n> | |||
<BuildModes Count="1"> | |||
<Item1 Name="Default" Default="True"/> | |||
</BuildModes> | |||
<PublishOptions> | |||
<Version Value="2"/> | |||
</PublishOptions> | |||
<RunParams> | |||
<local> | |||
<FormatVersion Value="1"/> | |||
</local> | |||
</RunParams> | |||
<RequiredPackages Count="1"> | |||
<Item1> | |||
<PackageName Value="LCL"/> | |||
</Item1> | |||
</RequiredPackages> | |||
<Units Count="3"> | |||
<Unit0> | |||
<Filename Value="example.lpr"/> | |||
<IsPartOfProject Value="True"/> | |||
</Unit0> | |||
<Unit1> | |||
<Filename Value="uMainForm.pas"/> | |||
<IsPartOfProject Value="True"/> | |||
<ComponentName Value="MainForm"/> | |||
<HasResources Value="True"/> | |||
<ResourceBaseClass Value="Form"/> | |||
</Unit1> | |||
<Unit2> | |||
<Filename Value="..\..\ulibTextSuite.pas"/> | |||
<IsPartOfProject Value="True"/> | |||
</Unit2> | |||
</Units> | |||
</ProjectOptions> | |||
<CompilerOptions> | |||
<Version Value="11"/> | |||
<PathDelim Value="\"/> | |||
<Target> | |||
<Filename Value="example"/> | |||
</Target> | |||
<SearchPaths> | |||
<IncludeFiles Value="$(ProjOutDir)"/> | |||
<OtherUnitFiles Value="..\.."/> | |||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> | |||
</SearchPaths> | |||
<Linking> | |||
<Debugging> | |||
<UseHeaptrc Value="True"/> | |||
<UseExternalDbgSyms Value="True"/> | |||
</Debugging> | |||
<Options> | |||
<Win32> | |||
<GraphicApplication Value="True"/> | |||
</Win32> | |||
</Options> | |||
</Linking> | |||
<Other> | |||
<CompilerMessages> | |||
<IgnoredMessages idx5024="True"/> | |||
</CompilerMessages> | |||
<CustomOptions Value="-dDUMP_HEAPTRACE"/> | |||
</Other> | |||
</CompilerOptions> | |||
<Debugging> | |||
<Exceptions Count="3"> | |||
<Item1> | |||
<Name Value="EAbort"/> | |||
</Item1> | |||
<Item2> | |||
<Name Value="ECodetoolError"/> | |||
</Item2> | |||
<Item3> | |||
<Name Value="EFOpenError"/> | |||
</Item3> | |||
</Exceptions> | |||
</Debugging> | |||
</CONFIG> |
@@ -1,31 +1,31 @@ | |||
program example; | |||
{$mode objfpc}{$H+} | |||
uses | |||
{$IFDEF UNIX}{$IFDEF UseCThreads} | |||
cthreads, | |||
{$ENDIF}{$ENDIF} | |||
Interfaces, SysUtils, Forms, uMainForm, ulibTextSuite; | |||
{$R *.res} | |||
{$IFDEF DUMP_HEAPTRACE} | |||
var | |||
heaptrcFile: String; | |||
{$ENDIF} | |||
begin | |||
{$IFDEF DUMP_HEAPTRACE} | |||
heaptrcFile := ChangeFileExt(Application.ExeName, '.heaptrc'); | |||
if (FileExists(heaptrcFile)) then | |||
DeleteFile(heaptrcFile); | |||
SetHeapTraceOutput(heaptrcFile); | |||
{$ENDIF} | |||
RequireDerivedFormResource := True; | |||
Application.Initialize; | |||
Application.CreateForm(TMainForm, MainForm); | |||
Application.Run; | |||
end. | |||
program example; | |||
{$mode objfpc}{$H+} | |||
uses | |||
{$IFDEF UNIX}{$IFDEF UseCThreads} | |||
cthreads, | |||
{$ENDIF}{$ENDIF} | |||
Interfaces, SysUtils, Forms, uMainForm, ulibTextSuite; | |||
{$R *.res} | |||
{$IFDEF DUMP_HEAPTRACE} | |||
var | |||
heaptrcFile: String; | |||
{$ENDIF} | |||
begin | |||
{$IFDEF DUMP_HEAPTRACE} | |||
heaptrcFile := ChangeFileExt(Application.ExeName, '.heaptrc'); | |||
if (FileExists(heaptrcFile)) then | |||
DeleteFile(heaptrcFile); | |||
SetHeapTraceOutput(heaptrcFile); | |||
{$ENDIF} | |||
RequireDerivedFormResource := True; | |||
Application.Initialize; | |||
Application.CreateForm(TMainForm, MainForm); | |||
Application.Run; | |||
end. | |||
@@ -1,13 +1,13 @@ | |||
object MainForm: TMainForm | |||
Left = 1121 | |||
Height = 500 | |||
Top = 232 | |||
Width = 640 | |||
Caption = 'libTextSuite' | |||
OnCreate = FormCreate | |||
OnDestroy = FormDestroy | |||
OnPaint = FormPaint | |||
OnResize = FormResize | |||
Position = poScreenCenter | |||
LCLVersion = '1.9.0.0' | |||
end | |||
object MainForm: TMainForm | |||
Left = 1121 | |||
Height = 500 | |||
Top = 232 | |||
Width = 640 | |||
Caption = 'libTextSuite' | |||
OnCreate = FormCreate | |||
OnDestroy = FormDestroy | |||
OnPaint = FormPaint | |||
OnResize = FormResize | |||
Position = poScreenCenter | |||
LCLVersion = '1.9.0.0' | |||
end |
@@ -1,4 +1,4 @@ | |||
{$DEFINE TS_ENABLE_OPENGL_SUPPORT} | |||
{$DEFINE TS_ENABLE_OPENGLES_SUPPORT} | |||
{$DEFINE TS_ENABLE_GDI_SUPPORT} | |||
{$DEFINE TS_ENABLE_FREETYPE_SUPPORT} | |||
{$DEFINE TS_ENABLE_OPENGL_SUPPORT} | |||
{$DEFINE TS_ENABLE_OPENGLES_SUPPORT} | |||
{$DEFINE TS_ENABLE_GDI_SUPPORT} | |||
{$DEFINE TS_ENABLE_FREETYPE_SUPPORT} |
@@ -1,117 +1,116 @@ | |||
library libTextSuite; | |||
{$mode objfpc}{$H+} | |||
uses | |||
Classes, SysUtils, | |||
ultsChar, ultsFontCreator, ultsGeneral, ultsPostProcessor, ultsTextBlock, | |||
ultsUtils, ultsContext, ultsFont, ultsImage, ultsRenderer, ultsTypes; | |||
exports | |||
ltsContextCreate, | |||
ltsContextGetCodePage, | |||
ltsContextGetDefaultChar, | |||
ltsContextSetCodePage, | |||
ltsContextSetDefaultChar, | |||
ltsContextAnsiToWide, | |||
ltsContextDestroy, | |||
ltsRendererCreate, | |||
ltsRendererCustomCreate, | |||
ltsRendererBeginBlock, | |||
ltsRendererEndBlock, | |||
ltsRendererAbortBlock, | |||
ltsRendererGetTextWidthA, | |||
ltsRendererGetTextWidthW, | |||
ltsRendererDestroy, | |||
ltsFontCreatorCreate, | |||
ltsFontCreatorGetFontByName, | |||
ltsFontCreatorGetFontByFile, | |||
ltsFontCreatorGetFontByStream, | |||
ltsFontCreatorDestroy, | |||
ltsFontGetPostProcessor, | |||
ltsFontGetTabWidth, | |||
ltsFontGetCharSpacing, | |||
ltsFontGetLineSpacing, | |||
ltsFontGetMetric, | |||
ltsFontGetFontname, | |||
ltsFontGetFacename, | |||
ltsFontGetStylename, | |||
ltsFontGetFullname, | |||
ltsFontGetCopyright, | |||
ltsFontSetPostProcessor, | |||
ltsFontSetTabWidth, | |||
ltsFontSetCharSpacing, | |||
ltsFontSetLineSpacing, | |||
ltsFontDestroy, | |||
ltsTextBlockGetRect, | |||
ltsTextBlockGetWidth, | |||
ltsTextBlockGetHeight, | |||
ltsTextBlockGetFlags, | |||
ltsTextBlockGetTop, | |||
ltsTextBlockGetLeft, | |||
ltsTextBlockGetVertAlign, | |||
ltsTextBlockGetHorzAlign, | |||
ltsTextBlockGetClipping, | |||
ltsTextBlockGetColor, | |||
ltsTextBlockGetFont, | |||
ltsTextBlockSetTop, | |||
ltsTextBlockSetLeft, | |||
ltsTextBlockSetVertAlign, | |||
ltsTextBlockSetHorzAlign, | |||
ltsTextBlockSetClipping, | |||
ltsTextBlockSetColor, | |||
ltsTextBlockSetFont, | |||
ltsTextBlockGetActualHeight, | |||
ltsTextBlockGetTextWidthA, | |||
ltsTextBlockGetTextWidthW, | |||
ltsTextBlockTextOutA, | |||
ltsTextBlockTextOutW, | |||
ltsTextBlockDestroy, | |||
ltsImageCreate, | |||
ltsImageIsEmpty, | |||
ltsImageGetWidth, | |||
ltsImageGetHeight, | |||
ltsImageGetLineSize, | |||
ltsImageGetDataSize, | |||
ltsImageGetFormat, | |||
ltsImageGetData, | |||
ltsImageGetScanline, | |||
ltsImageGetPixelAt, | |||
ltsImageAssign, | |||
ltsImageCreateEmpty, | |||
ltsImageLoadFromFunc, | |||
ltsImageResize, | |||
ltsImageFillColor, | |||
ltsImageFillPattern, | |||
ltsImageBlend, | |||
ltsImageBlur, | |||
ltsImageDestroy, | |||
ltsPostProcessorAddRange, | |||
ltsPostProcessorAddChars, | |||
ltsPostProcessorClearRanges, | |||
ltsPostProcessorExecute, | |||
ltsPostProcessorFillColorCreate, | |||
ltsPostProcessorFillPatterCreate, | |||
ltsPostProcessorBorderCreate, | |||
ltsPostProcessorShadowCreate, | |||
ltsPostProcessorCustomCreate, | |||
ltsPostProcessorDestroy, | |||
ltsCharGetCharCode, | |||
ltsCharGetGlyphMetric, | |||
ltsCharSetGlyphMetric, | |||
ltsInitialize, | |||
ltsGetVersion, | |||
ltsGetLastErrorCode, | |||
ltsGetLastErrorMsg, | |||
ltsFinalize; | |||
end. | |||
library libTextSuite; | |||
{$mode objfpc}{$H+} | |||
uses | |||
Classes, SysUtils, ultsChar, ultsFontCreator, ultsGeneral, ultsPostProcessor, ultsTextBlock, ultsUtils, ultsContext, | |||
ultsFont, ultsImage, ultsRenderer, ultsTypes, utsCharCache; | |||
exports | |||
ltsContextCreate, | |||
ltsContextGetCodePage, | |||
ltsContextGetDefaultChar, | |||
ltsContextSetCodePage, | |||
ltsContextSetDefaultChar, | |||
ltsContextAnsiToWide, | |||
ltsContextDestroy, | |||
ltsRendererCreate, | |||
ltsRendererCustomCreate, | |||
ltsRendererBeginBlock, | |||
ltsRendererEndBlock, | |||
ltsRendererAbortBlock, | |||
ltsRendererGetTextWidthA, | |||
ltsRendererGetTextWidthW, | |||
ltsRendererDestroy, | |||
ltsFontCreatorCreate, | |||
ltsFontCreatorGetFontByName, | |||
ltsFontCreatorGetFontByFile, | |||
ltsFontCreatorGetFontByStream, | |||
ltsFontCreatorDestroy, | |||
ltsFontGetPostProcessor, | |||
ltsFontGetTabWidth, | |||
ltsFontGetCharSpacing, | |||
ltsFontGetLineSpacing, | |||
ltsFontGetMetric, | |||
ltsFontGetFontname, | |||
ltsFontGetFacename, | |||
ltsFontGetStylename, | |||
ltsFontGetFullname, | |||
ltsFontGetCopyright, | |||
ltsFontSetPostProcessor, | |||
ltsFontSetTabWidth, | |||
ltsFontSetCharSpacing, | |||
ltsFontSetLineSpacing, | |||
ltsFontDestroy, | |||
ltsTextBlockGetRect, | |||
ltsTextBlockGetWidth, | |||
ltsTextBlockGetHeight, | |||
ltsTextBlockGetFlags, | |||
ltsTextBlockGetTop, | |||
ltsTextBlockGetLeft, | |||
ltsTextBlockGetVertAlign, | |||
ltsTextBlockGetHorzAlign, | |||
ltsTextBlockGetClipping, | |||
ltsTextBlockGetColor, | |||
ltsTextBlockGetFont, | |||
ltsTextBlockSetTop, | |||
ltsTextBlockSetLeft, | |||
ltsTextBlockSetVertAlign, | |||
ltsTextBlockSetHorzAlign, | |||
ltsTextBlockSetClipping, | |||
ltsTextBlockSetColor, | |||
ltsTextBlockSetFont, | |||
ltsTextBlockGetActualHeight, | |||
ltsTextBlockGetTextWidthA, | |||
ltsTextBlockGetTextWidthW, | |||
ltsTextBlockTextOutA, | |||
ltsTextBlockTextOutW, | |||
ltsTextBlockDestroy, | |||
ltsImageCreate, | |||
ltsImageIsEmpty, | |||
ltsImageGetWidth, | |||
ltsImageGetHeight, | |||
ltsImageGetLineSize, | |||
ltsImageGetDataSize, | |||
ltsImageGetFormat, | |||
ltsImageGetData, | |||
ltsImageGetScanline, | |||
ltsImageGetPixelAt, | |||
ltsImageAssign, | |||
ltsImageCreateEmpty, | |||
ltsImageLoadFromFunc, | |||
ltsImageResize, | |||
ltsImageFillColor, | |||
ltsImageFillPattern, | |||
ltsImageBlend, | |||
ltsImageBlur, | |||
ltsImageDestroy, | |||
ltsPostProcessorAddRange, | |||
ltsPostProcessorAddChars, | |||
ltsPostProcessorClearRanges, | |||
ltsPostProcessorExecute, | |||
ltsPostProcessorFillColorCreate, | |||
ltsPostProcessorFillPatternCreate, | |||
ltsPostProcessorBorderCreate, | |||
ltsPostProcessorShadowCreate, | |||
ltsPostProcessorCustomCreate, | |||
ltsPostProcessorDestroy, | |||
ltsCharGetCharCode, | |||
ltsCharGetGlyphMetric, | |||
ltsCharSetGlyphMetric, | |||
ltsInitialize, | |||
ltsGetVersion, | |||
ltsGetLastErrorCode, | |||
ltsGetLastErrorMsg, | |||
ltsFinalize; | |||
end. | |||
@@ -1 +1 @@ | |||
Subproject commit 81e189737fdd98dff433cf2a2f8fa652801229b7 | |||
Subproject commit f41d478213a734827d6d4a1b73ef79f40a2e15c8 |
@@ -1,77 +1,83 @@ | |||
unit ultsChar; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, ultsTypes; | |||
function ltsCharGetCharCode (aHandle: TltsCharHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
function ltsCharGetGlyphMetric(aHandle: TltsCharHandle; out aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
function ltsCharSetGlyphMetric(aHandle: TltsCharHandle; constref aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//ltsChar/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsCharGetCharCode(aHandle: TltsCharHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
var | |||
c: TtsChar; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckCharHandle(aHandle, c) | |||
then aValue := c.CharCode | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsCharGetGlyphMetric(aHandle: TltsCharHandle; out aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
var | |||
c: TtsChar; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckCharHandle(aHandle, c) | |||
then aValue := c.GlyphMetric | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsCharSetGlyphMetric(aHandle: TltsCharHandle; constref aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
var | |||
c: TtsChar; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckCharHandle(aHandle, c) | |||
then c.GlyphMetric := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
end. | |||
unit ultsChar; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, ultsTypes; | |||
function ltsCharGetCharCode (aHandle: TltsCharHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
function ltsCharGetGlyphMetric(aHandle: TltsCharHandle; out aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
function ltsCharSetGlyphMetric(aHandle: TltsCharHandle; constref aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils{$IFDEF DEBUG}, uutlLogger{$ENDIF}; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//ltsChar/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsCharGetCharCode(aHandle: TltsCharHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
var | |||
c: TtsChar; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.log(nil, 'ltsCharGetCharCode(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckCharHandle(aHandle, c) | |||
then aValue := c.CharCode | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.log(nil, 'ltsCharGetCharCode=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsCharGetGlyphMetric(aHandle: TltsCharHandle; out aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
var | |||
c: TtsChar; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.log(nil, 'ltsCharGetGlyphMetric(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckCharHandle(aHandle, c) | |||
then aValue := c.GlyphMetric | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.log(nil, 'ltsCharGetGlyphMetric=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsCharSetGlyphMetric(aHandle: TltsCharHandle; constref aValue: TtsGlyphMetric): TltsErrorCode; stdcall; | |||
var | |||
c: TtsChar; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.log(nil, 'ltsCharSetGlyphMetric(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckCharHandle(aHandle, c) | |||
then c.GlyphMetric := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.log(nil, 'ltsCharSetGlyphMetric=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
end. | |||
@@ -1,187 +1,200 @@ | |||
unit ultsContext; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, utsUtils, | |||
ultsTypes; | |||
type | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsContext = class(TtsContext) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
function ltsContextCreate (): TltsContextHandle; stdcall; | |||
function ltsContextGetCodePage (const aHandle: TltsContextHandle; out aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
function ltsContextGetDefaultChar (const aHandle: TltsContextHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
function ltsContextSetCodePage (const aHandle: TltsContextHandle; aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
function ltsContextSetDefaultChar (const aHandle: TltsContextHandle; aValue: WideChar): TltsErrorCode; stdcall; | |||
function ltsContextAnsiToWide (const aHandle: TltsContextHandle; aText: PAnsiChar): PWideChar; stdcall; | |||
function ltsContextDestroy (const aHandle: TltsContextHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils; | |||
var | |||
WideStringBuffer: WideString; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsContext/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsContext.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//Context/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextCreate: TltsContextHandle; stdcall; | |||
var | |||
c: TltsContext; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckIfInitialized then | |||
exit; | |||
c := TltsContext.Create; | |||
AddReference(ltsObjTypeContext, c); | |||
result := c; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextGetCodePage(const aHandle: TltsContextHandle; out aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then aCodePage := c.CodePage | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextGetDefaultChar(const aHandle: TltsContextHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then aValue := c.DefaultChar | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextSetCodePage(const aHandle: TltsContextHandle; aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) then begin | |||
if not ValidateCodePage(aCodePage) then begin | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid enum value for CodePage', [aCodePage])); | |||
result := LastErrorCode; | |||
end else | |||
c.CodePage := aCodePage; | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextSetDefaultChar(const aHandle: TltsContextHandle; aValue: WideChar): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then c.DefaultChar := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextAnsiToWide(const aHandle: TltsContextHandle; aText: PAnsiChar): PWideChar; stdcall; | |||
var | |||
c: TtsContext; | |||
w: PWideChar; | |||
begin | |||
try | |||
result := nil; | |||
if CheckContextHandle(aHandle, c) then begin | |||
w := c.AnsiToWide(aText); | |||
if not Assigned(w) then | |||
exit; | |||
WideStringBuffer := w; | |||
tsStrDispose(w); | |||
result := PWideChar(WideStringBuffer); | |||
end else | |||
result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextDestroy(const aHandle: TltsContextHandle): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then DelReference(ltsObjTypeContext, c) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
end. | |||
unit ultsContext; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, utsUtils, | |||
ultsTypes; | |||
type | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsContext = class(TtsContext) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
function ltsContextCreate (): TltsContextHandle; stdcall; | |||
function ltsContextGetCodePage (const aHandle: TltsContextHandle; out aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
function ltsContextGetDefaultChar (const aHandle: TltsContextHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
function ltsContextSetCodePage (const aHandle: TltsContextHandle; aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
function ltsContextSetDefaultChar (const aHandle: TltsContextHandle; aValue: WideChar): TltsErrorCode; stdcall; | |||
function ltsContextAnsiToWide (const aHandle: TltsContextHandle; aText: PAnsiChar): PWideChar; stdcall; | |||
function ltsContextDestroy (const aHandle: TltsContextHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils {$IFDEF DEBUG}, uutlLogger{$ENDIF}; | |||
var | |||
WideStringBuffer: WideString; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsContext/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsContext.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//Context/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextCreate: TltsContextHandle; stdcall; | |||
var | |||
c: TltsContext; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckIfInitialized then | |||
exit; | |||
c := TltsContext.Create; | |||
AddReference(ltsObjTypeContext, c); | |||
result := c; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextCreate=%p', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextGetCodePage(const aHandle: TltsContextHandle; out aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextGetCodePage(Handle=%p; aCodePage=%p)', [aHandle, @aCodePage]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then aCodePage := c.CodePage | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextGetCodePage=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextGetDefaultChar(const aHandle: TltsContextHandle; out aValue: WideChar): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextGetDefaultChar(Handle=%p; aValue=%p)', [aHandle, @aValue]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then aValue := c.DefaultChar | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextGetDefaultChar=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextSetCodePage(const aHandle: TltsContextHandle; aCodePage: TtsCodePage): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextSetCodePage(Handle=%p; aCodePage=%d)', [aHandle, Integer(aCodePage)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) then begin | |||
if not ValidateCodePage(aCodePage) then begin | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid enum value for CodePage', [aCodePage])); | |||
result := LastErrorCode; | |||
end else | |||
c.CodePage := aCodePage; | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextSetCodePage=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextSetDefaultChar(const aHandle: TltsContextHandle; aValue: WideChar): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextSetDefaultChar(Handle=%p; aValue=%d)', [aHandle, Integer(aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then c.DefaultChar := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextSetDefaultChar=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextAnsiToWide(const aHandle: TltsContextHandle; aText: PAnsiChar): PWideChar; stdcall; | |||
var | |||
c: TtsContext; | |||
w: PWideChar; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextAnsiToWide(Handle=%p; aText=%p)', [aHandle, aText]);{$ENDIF} | |||
result := nil; | |||
if CheckContextHandle(aHandle, c) then begin | |||
w := c.AnsiToWide(aText); | |||
if not Assigned(w) then | |||
exit; | |||
WideStringBuffer := w; | |||
tsStrDispose(w); | |||
result := PWideChar(WideStringBuffer); | |||
end else | |||
result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextAnsiToWide=%p', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsContextDestroy(const aHandle: TltsContextHandle): TltsErrorCode; stdcall; | |||
var | |||
c: TtsContext; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextDestroy(Handle=%p)', [aHandle]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckContextHandle(aHandle, c) | |||
then DelReference(ltsObjTypeContext, c) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsContextDestroy=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
end. | |||
@@ -1,306 +1,336 @@ | |||
unit ultsFont; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, | |||
ultsTypes; | |||
function ltsFontGetPostProcessor (aHandle: TltsFontHandle): TltsPostProcessorHandle; stdcall; | |||
function ltsFontGetTabWidth (aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontGetCharSpacing (aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontGetLineSpacing (aHandle: TltsFontHandle; out aValue: Single): TltsErrorCode; stdcall; | |||
function ltsFontGetMetric (aHandle: TltsFontHandle; out aValue: TtsFontMetric): TltsErrorCode; stdcall; | |||
function ltsFontGetFontname (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetFacename (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetStylename (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetFullname (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetCopyright (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontSetPostProcessor (aHandle: TltsFontHandle; aValue: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
function ltsFontSetTabWidth (aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontSetCharSpacing (aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontSetLineSpacing (aHandle: TltsFontHandle; aValue: Single): TltsErrorCode; stdcall; | |||
function ltsFontDestroy (aHandle: TltsFontHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//Font////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetPostProcessor(aHandle: TltsFontHandle): TltsPostProcessorHandle; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckFontHandle(aHandle, f) | |||
then result := f.PostProcessor | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetTabWidth(aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.TabWidth | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetCharSpacing(aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.CharSpacing | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetLineSpacing(aHandle: TltsFontHandle; out aValue: Single): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.LineSpacing | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetMetric(aHandle: TltsFontHandle; out aValue: TtsFontMetric): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.Metric | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetFontname(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.Fontname) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetFacename(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.FaceName) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetStylename(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.StyleName) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetFullname(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.FullName) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetCopyright(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.Copyright) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetPostProcessor(aHandle: TltsFontHandle; aValue: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
p: TtsPostProcessor; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) and CheckPostProcessorHandle(aValue, TtsPostProcessor, p) | |||
then f.PostProcessor := p | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetTabWidth(aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then f.TabWidth := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetCharSpacing(aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then f.CharSpacing := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetLineSpacing(aHandle: TltsFontHandle; aValue: Single): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then f.LineSpacing := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontDestroy(aHandle: TltsFontHandle): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) then begin | |||
DelReference(ltsObjTypeFont, f); | |||
FreeAndNil(f); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
end. | |||
unit ultsFont; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, | |||
ultsTypes; | |||
function ltsFontGetPostProcessor (aHandle: TltsFontHandle): TltsPostProcessorHandle; stdcall; | |||
function ltsFontGetTabWidth (aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontGetCharSpacing (aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontGetLineSpacing (aHandle: TltsFontHandle; out aValue: Single): TltsErrorCode; stdcall; | |||
function ltsFontGetMetric (aHandle: TltsFontHandle; out aValue: TtsFontMetric): TltsErrorCode; stdcall; | |||
function ltsFontGetFontname (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetFacename (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetStylename (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetFullname (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontGetCopyright (aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
function ltsFontSetPostProcessor (aHandle: TltsFontHandle; aValue: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
function ltsFontSetTabWidth (aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontSetCharSpacing (aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
function ltsFontSetLineSpacing (aHandle: TltsFontHandle; aValue: Single): TltsErrorCode; stdcall; | |||
function ltsFontDestroy (aHandle: TltsFontHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils {$IFDEF DEBUG}, uutlLogger{$ENDIF}; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//Font////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetPostProcessor(aHandle: TltsFontHandle): TltsPostProcessorHandle; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetPostProcessor(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckFontHandle(aHandle, f) | |||
then result := f.PostProcessor | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetPostProcessor=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetTabWidth(aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetTabWidth(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.TabWidth | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetTabWidth=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetCharSpacing(aHandle: TltsFontHandle; out aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetCharSpacing(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.CharSpacing | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetCharSpacing=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetLineSpacing(aHandle: TltsFontHandle; out aValue: Single): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetLineSpacing(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.LineSpacing | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetLineSpacing=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetMetric(aHandle: TltsFontHandle; out aValue: TtsFontMetric): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetMetric(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then aValue := f.Metric | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetMetric=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetFontname(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetFontname(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.Fontname) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetFontname=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetFacename(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetFacename(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.FaceName) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetFacename=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetStylename(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetStylename(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.StyleName) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetStylename=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetFullname(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetFullname(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.FullName) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetFullname=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontGetCopyright(aHandle: TltsFontHandle): PAnsiChar; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetCopyright(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckFontHandle(aHandle, f) | |||
then result := PAnsiChar(f.Names.Copyright) | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontGetCopyright=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetPostProcessor(aHandle: TltsFontHandle; aValue: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
p: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetPostProcessor(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) and CheckPostProcessorHandle(aValue, TtsPostProcessor, p) | |||
then f.PostProcessor := p | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetPostProcessor=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetTabWidth(aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetTabWidth(Handle=%p; Value=%d)', [Pointer(aHandle), aValue]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then f.TabWidth := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetTabWidth=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetCharSpacing(aHandle: TltsFontHandle; aValue: Integer): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetCharSpacing(Handle=%p; Value=%d)', [Pointer(aHandle), aValue]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then f.CharSpacing := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetCharSpacing=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontSetLineSpacing(aHandle: TltsFontHandle; aValue: Single): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetLineSpacing(Handle=%p; Value=%f)', [Pointer(aHandle), aValue]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) | |||
then f.LineSpacing := aValue | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontSetLineSpacing=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontDestroy(aHandle: TltsFontHandle): TltsErrorCode; stdcall; | |||
var | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontDestroy(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontHandle(aHandle, f) then begin | |||
DelReference(ltsObjTypeFont, f); | |||
FreeAndNil(f); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontDestroy=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
end. | |||
@@ -1,196 +1,207 @@ | |||
unit ultsFontCreator; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, | |||
ultsTypes; | |||
function ltsFontCreatorCreate (aHandle: TltsContextHandle; aType: TltsFontCreatorType): TltsFontCreatorHandle; stdcall; | |||
function ltsFontCreatorGetFontByName (aHandle: TltsFontCreatorHandle; aFontname: PAnsiChar; aSize: Integer; | |||
aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
function ltsFontCreatorGetFontByFile (aHandle: TltsFontCreatorHandle; aFilename: PAnsiChar; aSize: Integer; | |||
aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
function ltsFontCreatorGetFontByStream(aHandle: TltsFontCreatorHandle; aStream: PltsStream; aSize: Integer; | |||
aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
function ltsFontCreatorDestroy (aHandle: TltsFontCreatorHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
utsUtils, | |||
ultsUtils; | |||
type | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsFontCreatorFreeType = class(TtsFontCreatorFreeType) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsFontCreatorGDI = class(TtsFontCreatorGDI) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsFontCreatorFreeType/////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsFontCreatorFreeType.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsFontCreatorGDI//////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsFontCreatorGDI.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//FontCreato/////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorCreate(aHandle: TltsContextHandle; aType: TltsFontCreatorType): TltsFontCreatorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
fc: TtsFontCreator; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckContextHandle(aHandle, c) then | |||
exit; | |||
case aType of | |||
ltsFontCreatorFreeType: fc := TltsFontCreatorFreeType.Create(c); | |||
ltsFontCreatorGDI: fc := TltsFontCreatorGDI.Create(c); | |||
// TODO ltsRendererCustom: r := TltsRendererCustom.Create(c, aFormat); | |||
else | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid font creator type', [aType])); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFontCreator, fc); | |||
result := fc; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorGetFontByName(aHandle: TltsFontCreatorHandle; aFontname: PAnsiChar; | |||
aSize: Integer; aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
f: TtsFont; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckFontCreatorHandle(aHandle, fc) then | |||
exit; | |||
f := fc.GetFontByName(aFontname, aSize, aStyle, aAntiAliasing); | |||
if not Assigned(f) then begin | |||
SetLastError(ltsErrInvalidOperation, 'GetFontByName is not supported by this font creator'); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFont, f); | |||
result := f; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorGetFontByFile(aHandle: TltsFontCreatorHandle; aFilename: PAnsiChar; | |||
aSize: Integer; aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
f: TtsFont; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckFontCreatorHandle(aHandle, fc) then | |||
exit; | |||
f := fc.GetFontByFile(aFilename, aSize, aStyle, aAntiAliasing); | |||
if not Assigned(f) then begin | |||
SetLastError(ltsErrInvalidOperation, 'GetFontByFile is not supported by this font creator'); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFont, f); | |||
result := f; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorGetFontByStream(aHandle: TltsFontCreatorHandle; aStream: PltsStream; | |||
aSize: Integer; aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
f: TtsFont; | |||
s: TStream; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckFontCreatorHandle(aHandle, fc) then | |||
exit; | |||
s := TltsStreamImpl.Create(aStream); | |||
try | |||
f := fc.GetFontByStream(s, aSize, aStyle, aAntiAliasing); | |||
finally | |||
FreeAndNil(s); | |||
end; | |||
if not Assigned(f) then begin | |||
SetLastError(ltsErrInvalidOperation, 'GetFontByStream is not supported by this font creator'); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFont, f); | |||
result := f; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorDestroy(aHandle: TltsFontCreatorHandle): TltsErrorCode; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckFontCreatorHandle(aHandle, fc) then begin | |||
DelReference(ltsObjTypeFontCreator, fc); | |||
FreeAndNil(fc); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
end. | |||
unit ultsFontCreator; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, | |||
ultsTypes; | |||
function ltsFontCreatorCreate (aHandle: TltsContextHandle; aType: TltsFontCreatorType): TltsFontCreatorHandle; stdcall; | |||
function ltsFontCreatorGetFontByName (aHandle: TltsFontCreatorHandle; aFontname: PAnsiChar; aSize: Integer; | |||
aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
function ltsFontCreatorGetFontByFile (aHandle: TltsFontCreatorHandle; aFilename: PAnsiChar; aSize: Integer; | |||
aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
function ltsFontCreatorGetFontByStream(aHandle: TltsFontCreatorHandle; aStream: PltsStream; aSize: Integer; | |||
aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
function ltsFontCreatorDestroy (aHandle: TltsFontCreatorHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
utsUtils, | |||
ultsUtils | |||
{$IFDEF DEBUG}, uutlLogger{$ENDIF}; | |||
type | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsFontCreatorFreeType = class(TtsFontCreatorFreeType) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsFontCreatorGDI = class(TtsFontCreatorGDI) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsFontCreatorFreeType/////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsFontCreatorFreeType.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsFontCreatorGDI//////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsFontCreatorGDI.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//FontCreato/////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorCreate(aHandle: TltsContextHandle; aType: TltsFontCreatorType): TltsFontCreatorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
fc: TtsFontCreator; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorCreate(Handle=%p; Type=%d)', [Pointer(aHandle), Integer(aType)]);{$ENDIF} | |||
result := nil; | |||
if not CheckContextHandle(aHandle, c) then | |||
exit; | |||
case aType of | |||
ltsFontCreatorFreeType: fc := TltsFontCreatorFreeType.Create(c); | |||
ltsFontCreatorGDI: fc := TltsFontCreatorGDI.Create(c); | |||
// TODO ltsRendererCustom: r := TltsRendererCustom.Create(c, aFormat); | |||
else | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid font creator type', [aType])); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFontCreator, fc); | |||
result := fc; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorCreate=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorGetFontByName(aHandle: TltsFontCreatorHandle; aFontname: PAnsiChar; | |||
aSize: Integer; aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorGetFontByName(Handle=%p; Fontname=%p; Size=%d; Stype=%d; AntiAliasing=%d)', [Pointer(aHandle), Pointer(aFontname), Integer(aSize), Integer(aStyle), Integer(aAntiAliasing)]);{$ENDIF} | |||
result := nil; | |||
if not CheckFontCreatorHandle(aHandle, fc) then | |||
exit; | |||
f := fc.GetFontByName(aFontname, aSize, aStyle, aAntiAliasing); | |||
if not Assigned(f) then begin | |||
SetLastError(ltsErrInvalidOperation, 'GetFontByName is not supported by this font creator'); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFont, f); | |||
result := f; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorGetFontByName=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorGetFontByFile(aHandle: TltsFontCreatorHandle; aFilename: PAnsiChar; | |||
aSize: Integer; aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorGetFontByFile(Handle=%p; Filename=%p; Size=%d; Stype=%d; AntiAliasing=%d)', [Pointer(aHandle), Pointer(aFilename), Integer(aSize), Integer(aStyle), Integer(aAntiAliasing)]);{$ENDIF} | |||
result := nil; | |||
if not CheckFontCreatorHandle(aHandle, fc) then | |||
exit; | |||
f := fc.GetFontByFile(aFilename, aSize, aStyle, aAntiAliasing); | |||
if not Assigned(f) then begin | |||
SetLastError(ltsErrInvalidOperation, 'GetFontByFile is not supported by this font creator'); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFont, f); | |||
result := f; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorGetFontByFile=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorGetFontByStream(aHandle: TltsFontCreatorHandle; aStream: PltsStream; | |||
aSize: Integer; aStyle: TtsFontStyles; aAntiAliasing: TtsAntiAliasing): TltsFontHandle; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
f: TtsFont; | |||
s: TStream; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorGetFontByStream(Handle=%p; Stream=%p; Size=%d; Stype=%d; AntiAliasing=%d)', [Pointer(aHandle), Pointer(aStream), Integer(aSize), Integer(aStyle), Integer(aAntiAliasing)]);{$ENDIF} | |||
result := nil; | |||
if not CheckFontCreatorHandle(aHandle, fc) then | |||
exit; | |||
s := TltsStreamImpl.Create(aStream); | |||
try | |||
f := fc.GetFontByStream(s, aSize, aStyle, aAntiAliasing); | |||
finally | |||
FreeAndNil(s); | |||
end; | |||
if not Assigned(f) then begin | |||
SetLastError(ltsErrInvalidOperation, 'GetFontByStream is not supported by this font creator'); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeFont, f); | |||
result := f; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorGetFontByStream=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFontCreatorDestroy(aHandle: TltsFontCreatorHandle): TltsErrorCode; stdcall; | |||
var | |||
fc: TtsFontCreator; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorDestroy(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckFontCreatorHandle(aHandle, fc) then begin | |||
DelReference(ltsObjTypeFontCreator, fc); | |||
FreeAndNil(fc); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsFontCreatorDestroy=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
end. | |||
@@ -1,77 +1,120 @@ | |||
unit ultsGeneral; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
ultsTypes; | |||
function ltsInitialize: TltsErrorCode; stdcall; | |||
function ltsGetVersion: PAnsiChar; stdcall; | |||
function ltsGetLastErrorCode: TltsErrorCode; stdcall; | |||
function ltsGetLastErrorMsg: PAnsiChar; stdcall; | |||
function ltsFinalize: TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils; | |||
{$IFDEF DEBUG} | |||
const Version = 'DebugVersion'; | |||
{$ELSE} | |||
{$I utsTextSuiteVersion.inc} | |||
{$ENDIF} | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//General/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsInitialize: TltsErrorCode; stdcall; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
Initialize; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsGetVersion: PAnsiChar; stdcall; | |||
begin | |||
result := PAnsiChar(Version); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsGetLastErrorCode: TltsErrorCode; stdcall; | |||
begin | |||
result := LastErrorCode; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsGetLastErrorMsg: PAnsiChar; stdcall; | |||
begin | |||
result := PAnsiChar(LastErrorMsg); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFinalize: TltsErrorCode; stdcall; | |||
begin | |||
try | |||
Finalize; | |||
result := ltsErrNone; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
end. | |||
unit ultsGeneral; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
ultsTypes; | |||
function ltsInitialize: TltsErrorCode; stdcall; | |||
function ltsGetVersion: PAnsiChar; stdcall; | |||
function ltsGetLastErrorCode: TltsErrorCode; stdcall; | |||
function ltsGetLastErrorMsg: PAnsiChar; stdcall; | |||
function ltsFinalize: TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils | |||
{$IFDEF DEBUG}, uutlLogger, utsTextSuite, ultsRenderer, ultsPostProcessor{$ENDIF} | |||
; | |||
{$IFDEF DEBUG} | |||
const Version = 'DebugVersion'; | |||
{$ELSE} | |||
{$I utsTextSuiteVersion.inc} | |||
{$ENDIF} | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//General/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsInitialize: TltsErrorCode; stdcall; | |||
begin | |||
try | |||
{$IFDEF DEBUG} | |||
utlLogger.RegisterConsumer(TutlFileLogger.Create('libTextSuite.log', flmCreateNew, true)); | |||
utlLogger.Log(nil, 'libTextSuite initialized', []); | |||
utlLogger.Log(nil, 'Type Sizes:', []); | |||
utlLogger.Log(nil, ' TtsCodePage %d', [SizeOf(TtsCodePage )]); | |||
utlLogger.Log(nil, ' TtsFormat %d', [SizeOf(TtsFormat )]); | |||
utlLogger.Log(nil, ' TtsVertAlignment %d', [SizeOf(TtsVertAlignment )]); | |||
utlLogger.Log(nil, ' TtsHorzAlignment %d', [SizeOf(TtsHorzAlignment )]); | |||
utlLogger.Log(nil, ' TtsClipping %d', [SizeOf(TtsClipping )]); | |||
utlLogger.Log(nil, ' TtsAntiAliasing %d', [SizeOf(TtsAntiAliasing )]); | |||
utlLogger.Log(nil, ' TtsBlockFlag %d', [SizeOf(TtsBlockFlag )]); | |||
utlLogger.Log(nil, ' TtsBlockFlags %d', [SizeOf(TtsBlockFlags )]); | |||
utlLogger.Log(nil, ' TtsFontStyle %d', [SizeOf(TtsFontStyle )]); | |||
utlLogger.Log(nil, ' TtsFontStyles %d', [SizeOf(TtsFontStyles )]); | |||
utlLogger.Log(nil, ' TtsColorChannel %d', [SizeOf(TtsColorChannel )]); | |||
utlLogger.Log(nil, ' TtsColorChannels %d', [SizeOf(TtsColorChannels )]); | |||
utlLogger.Log(nil, ' TtsImageMode %d', [SizeOf(TtsImageMode )]); | |||
utlLogger.Log(nil, ' TtsImageModes %d', [SizeOf(TtsImageModes )]); | |||
utlLogger.Log(nil, ' TtsColor4f %d', [SizeOf(TtsColor4f )]); | |||
utlLogger.Log(nil, ' PtsColor4f %d', [SizeOf(PtsColor4f )]); | |||
utlLogger.Log(nil, ' TtsPosition %d', [SizeOf(TtsPosition )]); | |||
utlLogger.Log(nil, ' PtsPosition %d', [SizeOf(PtsPosition )]); | |||
utlLogger.Log(nil, ' TtsRect %d', [SizeOf(TtsRect )]); | |||
utlLogger.Log(nil, ' PtsRect %d', [SizeOf(PtsRect )]); | |||
utlLogger.Log(nil, ' TtsVector4f %d', [SizeOf(TtsVector4f )]); | |||
utlLogger.Log(nil, ' TtsMatrix4f %d', [SizeOf(TtsMatrix4f )]); | |||
utlLogger.Log(nil, ' TtsGlyphMetric %d', [SizeOf(TtsGlyphMetric )]); | |||
utlLogger.Log(nil, ' TtsTextMetric %d', [SizeOf(TtsTextMetric )]); | |||
utlLogger.Log(nil, ' TtsFontMetric %d', [SizeOf(TtsFontMetric )]); | |||
utlLogger.Log(nil, ' TtsBlendValueFunc %d', [SizeOf(TtsBlendValueFunc )]); | |||
utlLogger.Log(nil, ' TtsBlendColorFunc %d', [SizeOf(TtsBlendColorFunc )]); | |||
utlLogger.Log(nil, ' TltsRendererCustomData %d', [SizeOf(TltsRendererCustomData )]); | |||
utlLogger.Log(nil, ' TltsStream %d', [SizeOf(TltsStream )]); | |||
utlLogger.Log(nil, ' TltsPostProcessorCustomData %d', [SizeOf(TltsPostProcessorCustomData)]); | |||
{$ENDIF} | |||
result := ltsErrNone; | |||
Initialize; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsInitialize=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsGetVersion: PAnsiChar; stdcall; | |||
begin | |||
result := PAnsiChar(Version); | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsGetVersion=%p', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsGetLastErrorCode: TltsErrorCode; stdcall; | |||
begin | |||
result := LastErrorCode; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsGetLastErrorCode=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsGetLastErrorMsg: PAnsiChar; stdcall; | |||
begin | |||
result := PAnsiChar(LastErrorMsg); | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsGetLastErrorMsg=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsFinalize: TltsErrorCode; stdcall; | |||
begin | |||
try | |||
Finalize; | |||
result := ltsErrNone; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsGetLastErrorCode=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
end. | |||
@@ -1,458 +1,496 @@ | |||
unit ultsImage; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, | |||
ultsTypes; | |||
type | |||
TltsImageLoadFunc = procedure(aHandle: TltsImageHandle; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer); stdcall; | |||
TltsImageBlendFunc = procedure(aHandle: TltsImageHandle; aSrc, aDst: TtsColor4f; out aResult: TtsColor4f; aArgs: Pointer); stdcall; | |||
function ltsImageCreate (aContext: TltsContextHandle): TltsImageHandle; stdcall; | |||
function ltsImageIsEmpty (aHandle: TltsImageHandle; out aValue: Boolean): TltsErrorCode; stdcall; | |||
function ltsImageGetWidth (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetHeight (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetLineSize (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetDataSize (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetFormat (aHandle: TltsImageHandle; out aValue: TtsFormat): TltsErrorCode; stdcall; | |||
function ltsImageGetData (aHandle: TltsImageHandle): Pointer; stdcall; | |||
function ltsImageGetScanline (aHandle: TltsImageHandle; aIndex: Integer): Pointer; stdcall; | |||
function ltsImageGetPixelAt (aHandle: TltsImageHandle; aX, aY: Integer; out aColor: TtsColor4f): TltsErrorCode; stdcall; | |||
function ltsImageAssign (aHandle, aSource: TltsImageHandle): TltsErrorCode; stdcall; | |||
function ltsImageCreateEmpty (aHandle: TltsImageHandle; aFormat: TtsFormat; aWidth, aHeight: Integer): TltsErrorCode; stdcall; | |||
function ltsImageLoadFromFunc (aHandle: TltsImageHandle; aCallback: TltsImageLoadFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
function ltsImageResize (aHandle: TltsImageHandle; aWidth, aHeight, aX, aY: Integer): TltsErrorCode; stdcall; | |||
function ltsImageFillColor (aHandle: TltsImageHandle; aColor: TtsColor4f; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
function ltsImageFillPattern (aHandle, aPattern: TltsImageHandle; aX, aY: Integer; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
function ltsImageBlend (aHandle, aSource: TltsImageHandle; aX, aY: Integer; aBlendFunc: TltsImageBlendFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
function ltsImageBlur (aHandle: TltsImageHandle; aHorzRad, aHorzStr, aVertRad, aVertStr: Single; aMask: TtsColorChannels): TltsErrorCode; stdcall; | |||
function ltsImageDestroy (aHandle: TltsImageHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils, utsUtils; | |||
type | |||
PLoadArgs = ^TLoadArgs; | |||
TLoadArgs = packed record | |||
args: Pointer; | |||
handle: TltsImageHandle; | |||
callback: TltsImageLoadFunc | |||
end; | |||
PBlendArgs = ^TBlendArgs; | |||
TBlendArgs = packed record | |||
args: Pointer; | |||
handle: TltsImageHandle; | |||
callback: TltsImageBlendFunc; | |||
end; | |||
procedure ImageLoadCallback(const aImage: TtsImage; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer); | |||
var | |||
p: PLoadArgs; | |||
begin | |||
p := PLoadArgs(aArgs); | |||
p^.callback(p^.handle, X, Y, aPixel, p^.args); | |||
end; | |||
function ImageBlendCallback(const aSrc, aDst: TtsColor4f; aArgs: Pointer): TtsColor4f; | |||
var | |||
p: PBlendArgs; | |||
begin | |||
p := PBlendArgs(aArgs); | |||
p^.callback(p^.handle, aSrc, aDst, result, p^.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//ltsImage////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageCreate(aContext: TltsContextHandle): TltsImageHandle; stdcall; | |||
var | |||
img: TtsImage; | |||
c: TtsContext; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckContextHandle(aContext, c) then | |||
exit; | |||
img := TtsImage.Create(c); | |||
AddReference(ltsObjTypeImage, img); | |||
result := img; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageIsEmpty(aHandle: TltsImageHandle; out aValue: Boolean): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) | |||
then aValue := img.IsEmpty | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetWidth(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.Width | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetHeight(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.Height | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetLineSize(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.LineSize | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetDataSize(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.DataSize | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetFormat(aHandle: TltsImageHandle; out aValue: TtsFormat): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) | |||
then aValue := img.Format | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetData(aHandle: TltsImageHandle): Pointer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.Data | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetScanline(aHandle: TltsImageHandle; aIndex: Integer): Pointer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
if CheckImageHandle(aHandle, img) then begin | |||
result := img.Scanline[aIndex]; | |||
if not Assigned(result) then | |||
SetLastError(ltsErrInvalidValue, Format('index (%d) is out of range', [aIndex])); | |||
end else | |||
result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetPixelAt(aHandle: TltsImageHandle; aX, aY: Integer; out aColor: TtsColor4f): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
if not img.GetPixelAt(aX, aY, aColor) then begin | |||
SetLastError(ltsErrInvalidValue, Format('x (%d) or y (%d) is out of range', [aX, aY])); | |||
result := LastErrorCode; | |||
end; | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageAssign(aHandle, aSource: TltsImageHandle): TltsErrorCode; stdcall; | |||
var | |||
img, src: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) and CheckImageHandle(aSource, src) | |||
then img.Assign(src) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageCreateEmpty(aHandle: TltsImageHandle; aFormat: TtsFormat; aWidth, aHeight: Integer): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if not ValidateFormat(aFormat) then begin | |||
result := LastErrorCode; | |||
end else if (aWidth < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'width must be a positive value'); | |||
result := LastErrorCode; | |||
end else if (aHeight < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'height must be a positive value'); | |||
result := LastErrorCode; | |||
end else if not CheckImageHandle(aHandle, img) then begin | |||
result := LastErrorCode; | |||
end else | |||
img.CreateEmpty(aFormat, aWidth, aHeight); | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageLoadFromFunc(aHandle: TltsImageHandle; aCallback: TltsImageLoadFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
la: TLoadArgs; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
la.args := aArgs; | |||
la.callback := aCallback; | |||
la.handle := aHandle; | |||
img.LoadFromFunc(@ImageLoadCallback, @la); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageResize(aHandle: TltsImageHandle; aWidth, aHeight, aX, aY: Integer): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if (aWidth < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'width must be a positive value'); | |||
result := LastErrorCode; | |||
end else if (aHeight < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'height must be a positive value'); | |||
result := LastErrorCode; | |||
end else if not CheckImageHandle(aHandle, img) then begin | |||
result := LastErrorCode; | |||
end else | |||
img.Resize(aWidth, aHeight, aX, aY); | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageFillColor(aHandle: TltsImageHandle; aColor: TtsColor4f; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) | |||
then img.FillColor(aColor, aMask, aModes) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageFillPattern(aHandle, aPattern: TltsImageHandle; aX, aY: Integer; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
var | |||
img, pattern: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) and CheckImageHandle(aPattern, pattern) | |||
then img.FillPattern(pattern, aX, aY, aMask, aModes) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageBlend(aHandle, aSource: TltsImageHandle; aX, aY: Integer; aBlendFunc: TltsImageBlendFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
var | |||
img, src: TtsImage; | |||
ba: TBlendArgs; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) and CheckImageHandle(aSource, src) then begin | |||
ba.args := aArgs; | |||
ba.handle := aHandle; | |||
ba.callback := aBlendFunc; | |||
img.Blend(src, aX, aY, @ImageBlendCallback, @ba); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageBlur(aHandle: TltsImageHandle; aHorzRad, aHorzStr, aVertRad, aVertStr: Single; aMask: TtsColorChannels): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
horz, vert: TtsKernel1D; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
horz := TtsKernel1D.Create(aHorzRad, aHorzStr); | |||
vert := TtsKernel1D.Create(aVertRad, aVertStr); | |||
try | |||
img.Blur(horz, vert, aMask); | |||
finally | |||
FreeAndNil(horz); | |||
FreeAndNil(vert); | |||
end; | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageDestroy(aHandle: TltsImageHandle): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
DelReference(ltsObjTypeImage, img); | |||
FreeAndNil(img); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
end. | |||
unit ultsImage; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
utsTextSuite, | |||
ultsTypes; | |||
type | |||
TltsImageLoadFunc = procedure(aHandle: TltsImageHandle; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer); stdcall; | |||
TltsImageBlendFunc = procedure(aHandle: TltsImageHandle; aSrc, aDst: TtsColor4f; out aResult: TtsColor4f; aArgs: Pointer); stdcall; | |||
function ltsImageCreate (aContext: TltsContextHandle): TltsImageHandle; stdcall; | |||
function ltsImageIsEmpty (aHandle: TltsImageHandle; out aValue: Boolean): TltsErrorCode; stdcall; | |||
function ltsImageGetWidth (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetHeight (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetLineSize (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetDataSize (aHandle: TltsImageHandle): Integer; stdcall; | |||
function ltsImageGetFormat (aHandle: TltsImageHandle; out aValue: TtsFormat): TltsErrorCode; stdcall; | |||
function ltsImageGetData (aHandle: TltsImageHandle): Pointer; stdcall; | |||
function ltsImageGetScanline (aHandle: TltsImageHandle; aIndex: Integer): Pointer; stdcall; | |||
function ltsImageGetPixelAt (aHandle: TltsImageHandle; aX, aY: Integer; out aColor: TtsColor4f): TltsErrorCode; stdcall; | |||
function ltsImageAssign (aHandle, aSource: TltsImageHandle): TltsErrorCode; stdcall; | |||
function ltsImageCreateEmpty (aHandle: TltsImageHandle; aFormat: TtsFormat; aWidth, aHeight: Integer): TltsErrorCode; stdcall; | |||
function ltsImageLoadFromFunc (aHandle: TltsImageHandle; aCallback: TltsImageLoadFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
function ltsImageResize (aHandle: TltsImageHandle; aWidth, aHeight, aX, aY: Integer): TltsErrorCode; stdcall; | |||
function ltsImageFillColor (aHandle: TltsImageHandle; aColor: TtsColor4f; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
function ltsImageFillPattern (aHandle, aPattern: TltsImageHandle; aX, aY: Integer; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
function ltsImageBlend (aHandle, aSource: TltsImageHandle; aX, aY: Integer; aBlendFunc: TltsImageBlendFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
function ltsImageBlur (aHandle: TltsImageHandle; aHorzRad, aHorzStr, aVertRad, aVertStr: Single; aMask: TtsColorChannels): TltsErrorCode; stdcall; | |||
function ltsImageDestroy (aHandle: TltsImageHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils, utsUtils {$IFDEF DEBUG}, uutlLogger{$ENDIF}; | |||
type | |||
PLoadArgs = ^TLoadArgs; | |||
TLoadArgs = packed record | |||
args: Pointer; | |||
handle: TltsImageHandle; | |||
callback: TltsImageLoadFunc | |||
end; | |||
PBlendArgs = ^TBlendArgs; | |||
TBlendArgs = packed record | |||
args: Pointer; | |||
handle: TltsImageHandle; | |||
callback: TltsImageBlendFunc; | |||
end; | |||
procedure ImageLoadCallback(const aImage: TtsImage; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer); | |||
var | |||
p: PLoadArgs; | |||
begin | |||
p := PLoadArgs(aArgs); | |||
p^.callback(p^.handle, X, Y, aPixel, p^.args); | |||
end; | |||
function ImageBlendCallback(const aSrc, aDst: TtsColor4f; aArgs: Pointer): TtsColor4f; | |||
var | |||
p: PBlendArgs; | |||
begin | |||
p := PBlendArgs(aArgs); | |||
p^.callback(p^.handle, aSrc, aDst, result, p^.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//ltsImage////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageCreate(aContext: TltsContextHandle): TltsImageHandle; stdcall; | |||
var | |||
img: TtsImage; | |||
c: TtsContext; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreate(Context=%p)', [Pointer(aContext)]);{$ENDIF} | |||
result := nil; | |||
if not CheckContextHandle(aContext, c) then | |||
exit; | |||
img := TtsImage.Create(c); | |||
AddReference(ltsObjTypeImage, img); | |||
result := img; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreate=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageIsEmpty(aHandle: TltsImageHandle; out aValue: Boolean): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageIsEmpty(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) | |||
then aValue := img.IsEmpty | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageIsEmpty=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetWidth(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetWidth(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.Width | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetWidth=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetHeight(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetHeight(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.Height | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetHeight=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetLineSize(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetLineSize(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.LineSize | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetLineSize=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetDataSize(aHandle: TltsImageHandle): Integer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetDataSize(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.DataSize | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetDataSize=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetFormat(aHandle: TltsImageHandle; out aValue: TtsFormat): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetFormat(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) | |||
then aValue := img.Format | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetFormat=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetData(aHandle: TltsImageHandle): Pointer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetData(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
if CheckImageHandle(aHandle, img) | |||
then result := img.Data | |||
else result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetData=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetScanline(aHandle: TltsImageHandle; aIndex: Integer): Pointer; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetScanline(Handle=%p; Index=%d)', [Pointer(aHandle), aIndex]);{$ENDIF} | |||
if CheckImageHandle(aHandle, img) then begin | |||
result := img.Scanline[aIndex]; | |||
if not Assigned(result) then | |||
SetLastError(ltsErrInvalidValue, Format('index (%d) is out of range', [aIndex])); | |||
end else | |||
result := nil; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetScanline=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageGetPixelAt(aHandle: TltsImageHandle; aX, aY: Integer; out aColor: TtsColor4f): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetPixelAt(Handle=%p; X=%d; Y=%d; Color=%p)', [Pointer(aHandle), aX, aY, Pointer(@aColor)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
if not img.GetPixelAt(aX, aY, aColor) then begin | |||
SetLastError(ltsErrInvalidValue, Format('x (%d) or y (%d) is out of range', [aX, aY])); | |||
result := LastErrorCode; | |||
end; | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetPixelAt=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageAssign(aHandle, aSource: TltsImageHandle): TltsErrorCode; stdcall; | |||
var | |||
img, src: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageAssign(Handle=%p; Source=%p)', [Pointer(aHandle), Pointer(aSource)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) and CheckImageHandle(aSource, src) | |||
then img.Assign(src) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageAssign=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageCreateEmpty(aHandle: TltsImageHandle; aFormat: TtsFormat; aWidth, aHeight: Integer): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreateEmpty(Handle=%p; Format=%d; Width=%d; Height=%d)', [Pointer(aHandle), Integer(aFormat), aWidth, aHeight]);{$ENDIF} | |||
result := ltsErrNone; | |||
if not ValidateFormat(aFormat) then begin | |||
result := LastErrorCode; | |||
end else if (aWidth < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'width must be a positive value'); | |||
result := LastErrorCode; | |||
end else if (aHeight < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'height must be a positive value'); | |||
result := LastErrorCode; | |||
end else if not CheckImageHandle(aHandle, img) then begin | |||
result := LastErrorCode; | |||
end else | |||
img.CreateEmpty(aFormat, aWidth, aHeight); | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreateEmpty=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageLoadFromFunc(aHandle: TltsImageHandle; aCallback: TltsImageLoadFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
la: TLoadArgs; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageLoadFromFunc(Handle=%p; Callback=%p; Args=%p)', [Pointer(aHandle), Pointer(aCallback), aArgs]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
la.args := aArgs; | |||
la.callback := aCallback; | |||
la.handle := aHandle; | |||
img.LoadFromFunc(@ImageLoadCallback, @la); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageLoadFromFunc=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageResize(aHandle: TltsImageHandle; aWidth, aHeight, aX, aY: Integer): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageResize(Handle=%p; Width=%d; Height=%d; X=%d; Y=%d)', [Pointer(aHandle), aWidth, aHeight, aX, aY]);{$ENDIF} | |||
result := ltsErrNone; | |||
if (aWidth < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'width must be a positive value'); | |||
result := LastErrorCode; | |||
end else if (aHeight < 0) then begin | |||
SetLastError(ltsErrInvalidValue, 'height must be a positive value'); | |||
result := LastErrorCode; | |||
end else if not CheckImageHandle(aHandle, img) then begin | |||
result := LastErrorCode; | |||
end else | |||
img.Resize(aWidth, aHeight, aX, aY); | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageResize=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageFillColor(aHandle: TltsImageHandle; aColor: TtsColor4f; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillColor(Handle=%p; Color=(%f;%f;%f;%f); Mask=%d; Modes=(%d;%d;%d;%d))', [Pointer(aHandle), aColor.r, aColor.g, aColor.b, aColor.a, Integer(aMask), Integer(aModes[TtsColorChannel.tsChannelRed]), Integer(aModes[TtsColorChannel.tsChannelGreen]), Integer(aModes[TtsColorChannel.tsChannelBlue]), Integer(aModes[TtsColorChannel.tsChannelAlpha])]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) | |||
then img.FillColor(aColor, aMask, aModes) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillColor=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageFillPattern(aHandle, aPattern: TltsImageHandle; aX, aY: Integer; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall; | |||
var | |||
img, pattern: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillPattern(Handle=%p; Pattern=%p; X=%d; Y=%d; Mask=%d; Modes=(%d;%d;%d;%d))', [Pointer(aHandle), Pointer(aPattern), aX, aY, Integer(aMask), Integer(aModes[TtsColorChannel.tsChannelRed]), Integer(aModes[TtsColorChannel.tsChannelGreen]), Integer(aModes[TtsColorChannel.tsChannelBlue]), Integer(aModes[TtsColorChannel.tsChannelAlpha])]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) and CheckImageHandle(aPattern, pattern) | |||
then img.FillPattern(pattern, aX, aY, aMask, aModes) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillPattern=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageBlend(aHandle, aSource: TltsImageHandle; aX, aY: Integer; aBlendFunc: TltsImageBlendFunc; aArgs: Pointer): TltsErrorCode; stdcall; | |||
var | |||
img, src: TtsImage; | |||
ba: TBlendArgs; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlend(Handle=%p; Source=%p; X=%d; Y=%d; BlendFunc=%p; Args=%p)', [Pointer(aHandle), Pointer(aSource), aX, aY, Pointer(aBlendFunc), aArgs]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) and CheckImageHandle(aSource, src) then begin | |||
ba.args := aArgs; | |||
ba.handle := aHandle; | |||
ba.callback := aBlendFunc; | |||
img.Blend(src, aX, aY, @ImageBlendCallback, @ba); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlend=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageBlur(aHandle: TltsImageHandle; aHorzRad, aHorzStr, aVertRad, aVertStr: Single; aMask: TtsColorChannels): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
horz, vert: TtsKernel1D; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlur(Handle=%p; HorzRad=%f; HorzStr=%f; VertRad=%f; VertStr=%f; Mask=%d)', [Pointer(aHandle), aHorzRad, aHorzStr, aVertRad, aVertStr, Integer(aMask)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
horz := TtsKernel1D.Create(aHorzRad, aHorzStr); | |||
vert := TtsKernel1D.Create(aVertRad, aVertStr); | |||
try | |||
img.Blur(horz, vert, aMask); | |||
finally | |||
FreeAndNil(horz); | |||
FreeAndNil(vert); | |||
end; | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlur=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsImageDestroy(aHandle: TltsImageHandle): TltsErrorCode; stdcall; | |||
var | |||
img: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageDestroy(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckImageHandle(aHandle, img) then begin | |||
DelReference(ltsObjTypeImage, img); | |||
FreeAndNil(img); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageDestroy=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
end. | |||
@@ -1,284 +1,304 @@ | |||
unit ultsPostProcessor; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
ultsTypes, utsTextSuite; | |||
type | |||
TltsPostProcessorExecuteFunc = procedure(const aCharHandle: TltsCharHandle; const aImageHandle: TltsImageHandle; aArgs: Pointer); stdcall; | |||
PltsPostProcessorCustomData = ^TltsPostProcessorCustomData; | |||
TltsPostProcessorCustomData = packed record | |||
args: Pointer; | |||
execute: TltsPostProcessorExecuteFunc; | |||
end; | |||
TltsPostProcessorCustom = class(TtsPostProcessor) | |||
private | |||
fData: TltsPostProcessorCustomData; | |||
public | |||
function Execute(const aChar: TtsChar; const aImage: TtsImage): Boolean; override; | |||
constructor Create(const aContext: TtsContext; const aData: TltsPostProcessorCustomData); | |||
end; | |||
function ltsPostProcessorAddRange (aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aStart, aStop: WideChar): TltsErrorCode; stdcall; | |||
function ltsPostProcessorAddChars (aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aChars: PWideChar): TltsErrorCode; stdcall; | |||
function ltsPostProcessorClearRanges (aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
function ltsPostProcessorExecute (aHandle: TltsPostProcessorHandle; aChar: TltsCharHandle; aImage: TltsImageHandle): TltsErrorCode; stdcall; | |||
function ltsPostProcessorFillColorCreate (aContext: TltsContextHandle; aColor: TtsColor4f; | |||
aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorFillPatterCreate (aContext: TltsContextHandle; aPattern: TltsImageHandle; aOwnsPatter: Boolean; | |||
aPosition: TtsPosition; aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorBorderCreate (aContext: TltsContextHandle; aWidth, aStrength: Single; | |||
aColor: TtsColor4f; aKeepSize: Boolean): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorShadowCreate (aContext: TltsContextHandle; aRadius, aStrength: Single; | |||
aOffset: TtsPosition; aColor: TtsColor4f): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorCustomCreate (aContext: TltsContextHandle; constref aData: TltsPostProcessorCustomData): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorDestroy (aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//ltsPostProcessor////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorAddRange(aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aStart, aStop: WideChar): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) | |||
then pp.AddRange(aUsage, aStart, aStop) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorAddChars(aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aChars: PWideChar): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) | |||
then pp.AddChars(aUsage, aChars) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorClearRanges(aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) | |||
then pp.ClearRanges | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorExecute(aHandle: TltsPostProcessorHandle; aChar: TltsCharHandle; aImage: TltsImageHandle): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
c: TtsChar; | |||
i: TtsImage; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) and | |||
CheckCharHandle(aChar, c) and | |||
CheckImageHandle(aImage, i) | |||
then pp.Execute(c, i) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorFillColorCreate(aContext: TltsContextHandle; aColor: TtsColor4f; aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TtsPostProcessorFillColor.Create(c, aColor, aModes, aChannels); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorFillPatterCreate(aContext: TltsContextHandle; aPattern: TltsImageHandle; aOwnsPatter: Boolean; aPosition: TtsPosition; aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
img: TtsImage; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := nil; | |||
img := nil; | |||
if CheckContextHandle(aContext, c) and CheckImageHandle(aPattern, img) then begin | |||
pp := TtsPostProcessorFillPattern.Create(c, img, aOwnsPatter, aPosition, aModes, aChannels); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorBorderCreate(aContext: TltsContextHandle; aWidth, aStrength: Single; aColor: TtsColor4f; aKeepSize: Boolean): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TtsPostProcessorBorder.Create(c, aWidth, aStrength, aColor, aKeepSize); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorShadowCreate(aContext: TltsContextHandle; aRadius, aStrength: Single; aOffset: TtsPosition; aColor: TtsColor4f): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TtsPostProcessorShadow.Create(c, aRadius, aStrength, aOffset, aColor); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorCustomCreate(aContext: TltsContextHandle; constref aData: TltsPostProcessorCustomData): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TltsPostProcessorCustom.Create(c, aData); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorDestroy(aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) then begin | |||
if (pp is TtsPostProcessorFillPattern) then with (pp as TtsPostProcessorFillPattern) do begin | |||
if OwnsPattern then | |||
DelReference(ltsObjTypeImage, Pattern); | |||
end; | |||
DelReference(ltsObjTypePostProcessor, pp); | |||
FreeAndNil(pp); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsPostProcessorCustom/////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsPostProcessorCustom.Execute(const aChar: TtsChar; const aImage: TtsImage): Boolean; | |||
begin | |||
result := inherited Execute(aChar, aImage); | |||
if result then begin | |||
AddReference(ltsObjTypeChar, aChar); | |||
AddReference(ltsObjTypeImage, aImage); | |||
try | |||
fData.execute(aChar, aImage, fData.args); | |||
finally | |||
DelReference(ltsObjTypeChar, aChar); | |||
DelReference(ltsObjTypeImage, aImage); | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsPostProcessorCustom.Create(const aContext: TtsContext; const aData: TltsPostProcessorCustomData); | |||
begin | |||
inherited Create(aContext); | |||
fData := aData; | |||
end; | |||
end. | |||
unit ultsPostProcessor; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
ultsTypes, utsTextSuite; | |||
type | |||
TltsPostProcessorExecuteFunc = procedure(const aCharHandle: TltsCharHandle; const aImageHandle: TltsImageHandle; aArgs: Pointer); stdcall; | |||
PltsPostProcessorCustomData = ^TltsPostProcessorCustomData; | |||
TltsPostProcessorCustomData = packed record | |||
args: Pointer; | |||
execute: TltsPostProcessorExecuteFunc; | |||
end; | |||
TltsPostProcessorCustom = class(TtsPostProcessor) | |||
private | |||
fData: TltsPostProcessorCustomData; | |||
public | |||
function Execute(const aChar: TtsChar; const aImage: TtsImage): Boolean; override; | |||
constructor Create(const aContext: TtsContext; const aData: TltsPostProcessorCustomData); | |||
end; | |||
function ltsPostProcessorAddRange (aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aStart, aStop: WideChar): TltsErrorCode; stdcall; | |||
function ltsPostProcessorAddChars (aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aChars: PWideChar): TltsErrorCode; stdcall; | |||
function ltsPostProcessorClearRanges (aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
function ltsPostProcessorExecute (aHandle: TltsPostProcessorHandle; aChar: TltsCharHandle; aImage: TltsImageHandle): TltsErrorCode; stdcall; | |||
function ltsPostProcessorFillColorCreate (aContext: TltsContextHandle; aColor: TtsColor4f; | |||
aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorFillPatternCreate (aContext: TltsContextHandle; aPattern: TltsImageHandle; aOwnsPatter: Boolean; | |||
aPosition: TtsPosition; aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorBorderCreate (aContext: TltsContextHandle; aWidth, aStrength: Single; | |||
aColor: TtsColor4f; aKeepSize: Boolean): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorShadowCreate (aContext: TltsContextHandle; aRadius, aStrength: Single; | |||
aOffset: TtsPosition; aColor: TtsColor4f): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorCustomCreate (aContext: TltsContextHandle; constref aData: TltsPostProcessorCustomData): TltsPostProcessorHandle; stdcall; | |||
function ltsPostProcessorDestroy (aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils {$IFDEF DEBUG}, uutlLogger{$ENDIF}; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//ltsPostProcessor////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorAddRange(aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aStart, aStop: WideChar): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorAddRange(Handle=%p; Usage=%d; Start=%d; Stop=%d)', [Pointer(aHandle), Integer(aUsage), Integer(aStart), Integer(aStop)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) | |||
then pp.AddRange(aUsage, aStart, aStop) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorExecute=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorAddChars(aHandle: TltsPostProcessorHandle; aUsage: TtsCharRangeUsage; aChars: PWideChar): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorAddChars(Handle=%p; Usage=%d; Chars=%p)', [Pointer(aHandle), Integer(aUsage), Pointer(aChars)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if ValidateCharRangeUsage(aUsage) and CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) | |||
then pp.AddChars(aUsage, aChars) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorExecute=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorClearRanges(aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorClearRanges(Handle=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) | |||
then pp.ClearRanges | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorExecute=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorExecute(aHandle: TltsPostProcessorHandle; aChar: TltsCharHandle; aImage: TltsImageHandle): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
c: TtsChar; | |||
i: TtsImage; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorExecute(Handle=%p; Char=%p; Image=%p)', [Pointer(aHandle), Pointer(aChar), Pointer(aImage)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) and | |||
CheckCharHandle(aChar, c) and | |||
CheckImageHandle(aImage, i) | |||
then pp.Execute(c, i) | |||
else result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorExecute=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorFillColorCreate(aContext: TltsContextHandle; aColor: TtsColor4f; aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorFillColorCreate(Context=%p; Color=(%f;%f;%f;%f); Modes=(%d;%d;%d;%d); Channels=%d)', [Pointer(aContext), aColor.r, aColor.g, aColor.b, aColor.a, Integer(aModes[TtsColorChannel.tsChannelRed]), Integer(aModes[TtsColorChannel.tsChannelGreen]), Integer(aModes[TtsColorChannel.tsChannelBlue]), Integer(aModes[TtsColorChannel.tsChannelAlpha]), Integer(aChannels)]);{$ENDIF} | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TtsPostProcessorFillColor.Create(c, aColor, aModes, aChannels); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorFillColorCreate=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorFillPatternCreate(aContext: TltsContextHandle; aPattern: TltsImageHandle; aOwnsPatter: Boolean; aPosition: TtsPosition; aModes: TtsImageModes; aChannels: TtsColorChannels): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
img: TtsImage; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorFillPatternCreate(Context=%p; Pattern=%p; OwnsPattern=%d; Position=(%d;%d); Modes=(%d;%d;%d;%d); Channels=%d)', [Pointer(aContext), Pointer(aPattern), Integer(aOwnsPatter), aPosition.x, aPosition.y, Integer(aModes[TtsColorChannel.tsChannelRed]), Integer(aModes[TtsColorChannel.tsChannelGreen]), Integer(aModes[TtsColorChannel.tsChannelBlue]), Integer(aModes[TtsColorChannel.tsChannelAlpha]), Integer(aChannels)]);{$ENDIF} | |||
result := nil; | |||
img := nil; | |||
if CheckContextHandle(aContext, c) and CheckImageHandle(aPattern, img) then begin | |||
pp := TtsPostProcessorFillPattern.Create(c, img, aOwnsPatter, aPosition, aModes, aChannels); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorFillPatternCreate=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorBorderCreate(aContext: TltsContextHandle; aWidth, aStrength: Single; aColor: TtsColor4f; aKeepSize: Boolean): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorBorderCreate(Context=%p; Width=%f; Strength=%f; Color=(%f;%f;%f;%f); KeepSize=%d)', [Pointer(aContext), aWidth, aStrength, aColor.r, aColor.g, aColor.b, aColor.a, Integer(aKeepSize)]);{$ENDIF} | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TtsPostProcessorBorder.Create(c, aWidth, aStrength, aColor, aKeepSize); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorBorderCreate=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorShadowCreate(aContext: TltsContextHandle; aRadius, aStrength: Single; aOffset: TtsPosition; aColor: TtsColor4f): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorShadowCreate(Context=%p; Radius=%f; Strength=%f; Offset=(%d;%d); Color=(%f;%f;%f;%f))', [Pointer(aContext), aRadius, aStrength, aOffset.x, aOffset.y, aColor.r, aColor.g, aColor.b, aColor.a]);{$ENDIF} | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TtsPostProcessorShadow.Create(c, aRadius, aStrength, aOffset, aColor); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorShadowCreate=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorCustomCreate(aContext: TltsContextHandle; constref aData: TltsPostProcessorCustomData): TltsPostProcessorHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorCustomCreate(Context=%p; Data=%p)', [Pointer(aContext), Pointer(@aData)]);{$ENDIF} | |||
result := nil; | |||
if CheckContextHandle(aContext, c) then begin | |||
pp := TltsPostProcessorCustom.Create(c, aData); | |||
AddReference(ltsObjTypePostProcessor, pp); | |||
result := pp; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorCustomCreate=%p', [Pointer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsPostProcessorDestroy(aHandle: TltsPostProcessorHandle): TltsErrorCode; stdcall; | |||
var | |||
pp: TtsPostProcessor; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorDestroy(Context=%p)', [Pointer(aHandle)]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckPostProcessorHandle(aHandle, TtsPostProcessor, pp) then begin | |||
if (pp is TtsPostProcessorFillPattern) then with (pp as TtsPostProcessorFillPattern) do begin | |||
if OwnsPattern then | |||
DelReference(ltsObjTypeImage, Pattern); | |||
end; | |||
DelReference(ltsObjTypePostProcessor, pp); | |||
FreeAndNil(pp); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsPostProcessorDestroy=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsPostProcessorCustom/////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsPostProcessorCustom.Execute(const aChar: TtsChar; const aImage: TtsImage): Boolean; | |||
begin | |||
result := inherited Execute(aChar, aImage); | |||
if result then begin | |||
AddReference(ltsObjTypeChar, aChar); | |||
AddReference(ltsObjTypeImage, aImage); | |||
try | |||
fData.execute(aChar, aImage, fData.args); | |||
finally | |||
DelReference(ltsObjTypeChar, aChar); | |||
DelReference(ltsObjTypeImage, aImage); | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsPostProcessorCustom.Create(const aContext: TtsContext; const aData: TltsPostProcessorCustomData); | |||
begin | |||
inherited Create(aContext); | |||
fData := aData; | |||
end; | |||
end. | |||
@@ -1,394 +1,452 @@ | |||
unit ultsRenderer; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
ultsTypes, | |||
utsTextSuite, utsUtils, utsRenderer, utsTypes; | |||
type | |||
TltsRendererCustomBeginRender = procedure(aArgs: Pointer); stdcall; | |||
TltsRendererCustomEndRender = procedure(aArgs: Pointer); stdcall; | |||
TltsRendererCustomGetDrawPos = function (aArgs: Pointer): TtsPosition; stdcall; | |||
TltsRendererCustomSetDrawPos = procedure(const aValue: TtsPosition; aArgs: Pointer); stdcall; | |||
TltsRendererCustomMoveDrawPos = procedure(const aOffset: TtsPosition; aArgs: Pointer); stdcall; | |||
TltsRendererCustomSetColor = procedure(const aValue: TtsColor4f; aArgs: Pointer); stdcall; | |||
TltsRendererCustomRender = procedure(const aRef: Pointer; const aForcedWidth: Integer; aArgs: Pointer); stdcall; | |||
TltsRendererCustomCreateRef = function (const aChar: TltsCharHandle; const aImage: TltsImageHandle; aArgs: Pointer): Pointer; stdcall; | |||
TltsRendererCustomFreeRef = procedure(const aRef: Pointer; aArgs: Pointer); stdcall; | |||
PltsRendererCustomData = ^TltsRendererCustomData; | |||
TltsRendererCustomData = packed record | |||
args: Pointer; | |||
BeginRender: TltsRendererCustomBeginRender; | |||
EndRender: TltsRendererCustomEndRender; | |||
GetDrawPos: TltsRendererCustomGetDrawPos; | |||
SetDrawPos: TltsRendererCustomSetDrawPos; | |||
MoveDrawPos: TltsRendererCustomMoveDrawPos; | |||
SetColor: TltsRendererCustomSetColor; | |||
Render: TltsRendererCustomRender; | |||
CreatRef: TltsRendererCustomCreateRef; | |||
FreeRef: TltsRendererCustomFreeRef; | |||
end; | |||
function ltsRendererCreate (aHandle: TltsContextHandle; aType: TltsRendererType; aFormat: TtsFormat): TltsRendererHandle; stdcall; | |||
function ltsRendererCustomCreate (aHandle: TltsContextHandle; aFormat: TtsFormat; constref aData: TltsRendererCustomData): TltsRendererHandle; stdcall; | |||
function ltsRendererBeginBlock (aHandle: TltsRendererHandle; aTop, aLeft, aWidth, aHeight: Integer; aFlags: TtsBlockFlags): TltsTextBlockHandle; stdcall; | |||
function ltsRendererEndBlock (aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
function ltsRendererAbortBlock (aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
function ltsRendererGetTextWidthA(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PAnsiChar): Integer; stdcall; | |||
function ltsRendererGetTextWidthW(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PWideChar): Integer; stdcall; | |||
function ltsRendererDestroy (aHandle: TltsRendererHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
ultsUtils, dglOpenGL, dglOpenGLES; | |||
type | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsRendererOpenGL = class(TtsRendererOpenGL) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
constructor Create(const aContext: TtsContext; const aFormat: TtsFormat); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsRendererOpenGLES = class(TtsRendererOpenGLES) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
constructor Create(const aContext: TtsContext; const aFormat: TtsFormat); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsRendererCustom = class(TtsRenderer) | |||
{ TtsBlockRenderer } | |||
protected | |||
procedure BeginRender; override; | |||
procedure EndRender; override; | |||
function GetDrawPos: TtsPosition; override; | |||
procedure SetDrawPos(const aValue: TtsPosition); override; | |||
procedure MoveDrawPos(const aOffset: TtsPosition); override; | |||
procedure SetColor(const aValue: TtsColor4f); override; | |||
procedure Render(const aRenderRef: TtsRenderRef; const aForcedWidth: Integer); override; | |||
{ TtsRenderRefGenerator } | |||
public | |||
function CreateRenderRef(const aChar: TtsChar; const aImage: TtsImage): TtsRenderRef; override; | |||
procedure FreeRenderRef(const aRenderRef: TtsRenderRef); override; | |||
{ TltsRendererCustom } | |||
private | |||
fData: TltsRendererCustomData; | |||
public | |||
constructor Create(const aContext: TtsContext; const aFormat: TtsFormat; const aData: TltsRendererCustomData); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsRendererOpenGL//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererOpenGL.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsRendererOpenGL.Create(const aContext: TtsContext; const aFormat: TtsFormat); | |||
begin | |||
dglOpenGL.InitOpenGL; | |||
dglOpenGL.ReadExtensions; | |||
dglOpenGL.ReadImplementationProperties; | |||
inherited Create(aContext, aFormat); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsRendererOpenGLES////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererOpenGLES.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsRendererOpenGLES.Create(const aContext: TtsContext; const aFormat: TtsFormat); | |||
begin | |||
dglOpenGLES.InitOpenGLES; | |||
dglOpenGLES.ReadOpenGLCore; | |||
dglOpenGLES.ReadExtensions; | |||
dglOpenGLES.ReadCoreVersion; | |||
dglOpenGLES.ReadImplementationProperties; | |||
inherited Create(aContext, aFormat); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsRendererCustom//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererCustom.CreateRenderRef(const aChar: TtsChar; const aImage: TtsImage): TtsRenderRef; | |||
begin | |||
AddReference(ltsObjTypeChar, aChar); | |||
AddReference(ltsObjTypeImage, aImage); | |||
try | |||
if Assigned(fData.CreatRef) | |||
then result := fData.CreatRef(aChar, aImage, fData.args) | |||
else result := nil; | |||
finally | |||
DelReference(ltsObjTypeChar, aChar); | |||
DelReference(ltsObjTypeImage, aImage); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.FreeRenderRef(const aRenderRef: TtsRenderRef); | |||
begin | |||
if Assigned(fData.FreeRef) then | |||
fData.FreeRef(aRenderRef, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.BeginRender; | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.BeginRender(fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.EndRender; | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.BeginRender(fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererCustom.GetDrawPos: TtsPosition; | |||
begin | |||
if Assigned(fData.BeginRender) | |||
then result := fData.GetDrawPos(fData.args) | |||
else result := tsPosition(0, 0); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.SetDrawPos(const aValue: TtsPosition); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.SetDrawPos(aValue, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.MoveDrawPos(const aOffset: TtsPosition); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.MoveDrawPos(aOffset, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.SetColor(const aValue: TtsColor4f); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.SetColor(aValue, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.Render(const aRenderRef: TtsRenderRef; const aForcedWidth: Integer); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.Render(aRenderRef, aForcedWidth, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsRendererCustom.Create(const aContext: TtsContext; const aFormat: TtsFormat; const aData: TltsRendererCustomData); | |||
begin | |||
inherited Create(aContext, aFormat); | |||
fData := aData; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//Renderer////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererCreate(aHandle: TltsContextHandle; aType: TltsRendererType; aFormat: TtsFormat): TltsRendererHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
r: TtsRenderer; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckContextHandle(aHandle, c) then | |||
exit; | |||
if not ValidateFormat(aFormat) then begin | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid format', [aFormat])); | |||
exit; | |||
end; | |||
case aType of | |||
ltsRendererOpenGL: r := TltsRendererOpenGL.Create(c, aFormat); | |||
ltsRendererOpenGLES: r := TltsRendererOpenGLES.Create(c, aFormat); | |||
else | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid renderer type', [aType])); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeRenderer, r); | |||
result := r; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererCustomCreate(aHandle: TltsContextHandle; aFormat: TtsFormat; constref aData: TltsRendererCustomData): TltsRendererHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
r: TtsRenderer; | |||
begin | |||
try | |||
result := nil; | |||
if not CheckContextHandle(aHandle, c) then | |||
exit; | |||
if not ValidateFormat(aFormat) then begin | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid format', [aFormat])); | |||
exit; | |||
end; | |||
r := TltsRendererCustom.Create(c, aFormat, aData); | |||
AddReference(ltsObjTypeRenderer, r); | |||
result := r; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererBeginBlock(aHandle: TltsRendererHandle; aTop, aLeft, aWidth, aHeight: Integer; aFlags: TtsBlockFlags): TltsTextBlockHandle; stdcall; | |||
var | |||
r: TtsRenderer; | |||
b: TtsTextBlock; | |||
begin | |||
try | |||
result := nil; | |||
if CheckRendererHandle(aHandle, r) then begin | |||
b := r.BeginBlock(aTop, aLeft, aWidth, aHeight, aFlags); | |||
AddReference(ltsObjTypeTextBlock, b); | |||
result := b; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererEndBlock(aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
var | |||
r: TtsRenderer; | |||
b: TtsTextBlock; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckRendererHandle(aHandle, r) and CheckTextBlockHandle(aBlock, b) then begin | |||
DelReference(ltsObjTypeTextBlock, b); | |||
r.EndBlock(b); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererAbortBlock(aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
var | |||
r: TtsRenderer; | |||
b: TtsTextBlock; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckRendererHandle(aHandle, r) and CheckTextBlockHandle(aBlock, b) then begin | |||
DelReference(ltsObjTypeTextBlock, b); | |||
r.AbortBlock(b); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererGetTextWidthA(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PAnsiChar): Integer; stdcall; | |||
var | |||
r: TtsRenderer; | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckRendererHandle(aHandle, r) and CheckFontHandle(aFont, f) | |||
then result := r.GetTextWidthA(f, aText) | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererGetTextWidthW(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PWideChar): Integer; stdcall; | |||
var | |||
r: TtsRenderer; | |||
f: TtsFont; | |||
begin | |||
try | |||
if CheckRendererHandle(aHandle, r) and CheckFontHandle(aFont, f) | |||
then result := r.GetTextWidthW(f, aText) | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererDestroy(aHandle: TltsRendererHandle): TltsErrorCode; stdcall; | |||
var | |||
r: TtsRenderer; | |||
begin | |||
try | |||
result := ltsErrNone; | |||
if CheckRendererHandle(aHandle, r) then begin | |||
DelReference(ltsObjTypeRenderer, r); | |||
FreeAndNil(r); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
end; | |||
end. | |||
unit ultsRenderer; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
ultsTypes, | |||
utsTextSuite, utsUtils, utsRenderer, utsTypes; | |||
type | |||
TltsRendererCustomBeginRender = procedure(aArgs: Pointer); stdcall; | |||
TltsRendererCustomEndRender = procedure(aArgs: Pointer); stdcall; | |||
TltsRendererCustomGetDrawPos = function (aArgs: Pointer): TtsPosition; stdcall; | |||
TltsRendererCustomSetDrawPos = procedure(const aValue: TtsPosition; aArgs: Pointer); stdcall; | |||
TltsRendererCustomMoveDrawPos = procedure(const aOffset: TtsPosition; aArgs: Pointer); stdcall; | |||
TltsRendererCustomSetColor = procedure(const aValue: TtsColor4f; aArgs: Pointer); stdcall; | |||
TltsRendererCustomRender = procedure(const aRef: Pointer; const aForcedWidth: Integer; aArgs: Pointer); stdcall; | |||
TltsRendererCustomCreateRef = function (const aChar: TltsCharHandle; const aImage: TltsImageHandle; aArgs: Pointer): Pointer; stdcall; | |||
TltsRendererCustomFreeRef = procedure(const aRef: Pointer; aArgs: Pointer); stdcall; | |||
PltsRendererCustomData = ^TltsRendererCustomData; | |||
TltsRendererCustomData = packed record | |||
args: Pointer; | |||
BeginRender: TltsRendererCustomBeginRender; | |||
EndRender: TltsRendererCustomEndRender; | |||
GetDrawPos: TltsRendererCustomGetDrawPos; | |||
SetDrawPos: TltsRendererCustomSetDrawPos; | |||
MoveDrawPos: TltsRendererCustomMoveDrawPos; | |||
SetColor: TltsRendererCustomSetColor; | |||
Render: TltsRendererCustomRender; | |||
CreatRef: TltsRendererCustomCreateRef; | |||
FreeRef: TltsRendererCustomFreeRef; | |||
end; | |||
function ltsRendererCreate (aHandle: TltsContextHandle; aType: TltsRendererType; aFormat: TtsFormat): TltsRendererHandle; stdcall; | |||
function ltsRendererCustomCreate (aHandle: TltsContextHandle; aFormat: TtsFormat; constref aData: TltsRendererCustomData): TltsRendererHandle; stdcall; | |||
function ltsRendererBeginBlock (aHandle: TltsRendererHandle; aTop, aLeft, aWidth, aHeight: Integer; aFlags: TtsBlockFlags): TltsTextBlockHandle; stdcall; | |||
function ltsRendererEndBlock (aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
function ltsRendererAbortBlock (aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
function ltsRendererGetTextWidthA(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PAnsiChar): Integer; stdcall; | |||
function ltsRendererGetTextWidthW(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PWideChar): Integer; stdcall; | |||
function ltsRendererDestroy (aHandle: TltsRendererHandle): TltsErrorCode; stdcall; | |||
implementation | |||
uses | |||
{$IFDEF DEBUG}uutlLogger,{$ENDIF} | |||
ultsUtils, dglOpenGL, dglOpenGLES; | |||
type | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsRendererOpenGL = class(TtsRendererOpenGL) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsRendererOpenGLES = class(TtsRendererOpenGLES) | |||
public | |||
function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
TltsRendererCustom = class(TtsRenderer) | |||
{ TtsBlockRenderer } | |||
protected | |||
procedure BeginRender; override; | |||
procedure EndRender; override; | |||
function GetDrawPos: TtsPosition; override; | |||
procedure SetDrawPos(const aValue: TtsPosition); override; | |||
procedure MoveDrawPos(const aOffset: TtsPosition); override; | |||
procedure SetColor(const aValue: TtsColor4f); override; | |||
procedure Render(const aRenderRef: TtsRenderRef; const aForcedWidth: Integer); override; | |||
{ TtsRenderRefGenerator } | |||
public | |||
function CreateRenderRef(const aChar: TtsChar; const aImage: TtsImage): TtsRenderRef; override; | |||
procedure FreeRenderRef(const aRenderRef: TtsRenderRef); override; | |||
{ TltsRendererCustom } | |||
private | |||
fData: TltsRendererCustomData; | |||
public | |||
constructor Create(const aContext: TtsContext; const aFormat: TtsFormat; const aData: TltsRendererCustomData); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsRendererOpenGL//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererOpenGL.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsRendererOpenGLES////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererOpenGLES.DelSlave(const aSlave: TtsRefManager): Boolean; | |||
begin | |||
DelReference(aSlave); | |||
result := inherited DelSlave(aSlave); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsRendererCustom//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererCustom.CreateRenderRef(const aChar: TtsChar; const aImage: TtsImage): TtsRenderRef; | |||
begin | |||
AddReference(ltsObjTypeChar, aChar); | |||
AddReference(ltsObjTypeImage, aImage); | |||
try | |||
if Assigned(fData.CreatRef) | |||
then result := fData.CreatRef(aChar, aImage, fData.args) | |||
else result := nil; | |||
finally | |||
DelReference(ltsObjTypeChar, aChar); | |||
DelReference(ltsObjTypeImage, aImage); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.FreeRenderRef(const aRenderRef: TtsRenderRef); | |||
begin | |||
if Assigned(fData.FreeRef) then | |||
fData.FreeRef(aRenderRef, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.BeginRender; | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.BeginRender(fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.EndRender; | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.BeginRender(fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsRendererCustom.GetDrawPos: TtsPosition; | |||
begin | |||
if Assigned(fData.BeginRender) | |||
then result := fData.GetDrawPos(fData.args) | |||
else result := tsPosition(0, 0); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.SetDrawPos(const aValue: TtsPosition); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.SetDrawPos(aValue, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.MoveDrawPos(const aOffset: TtsPosition); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.MoveDrawPos(aOffset, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.SetColor(const aValue: TtsColor4f); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.SetColor(aValue, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure TltsRendererCustom.Render(const aRenderRef: TtsRenderRef; const aForcedWidth: Integer); | |||
begin | |||
if Assigned(fData.BeginRender) then | |||
fData.Render(aRenderRef, aForcedWidth, fData.args); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsRendererCustom.Create(const aContext: TtsContext; const aFormat: TtsFormat; const aData: TltsRendererCustomData); | |||
begin | |||
inherited Create(aContext, aFormat); | |||
fData := aData; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//Renderer////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererCreate(aHandle: TltsContextHandle; aType: TltsRendererType; aFormat: TtsFormat): TltsRendererHandle; stdcall; | |||
procedure CheckFunction(const aFunc: Pointer; const aName: String); | |||
begin | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererCreate.CheckFunction(Func=%p; Name=%s)', [aFunc, aName]);{$ENDIF} | |||
if not Assigned(aFunc) then | |||
raise Exception.Create('unable to load OpenGL function pointer: ' + aName); | |||
end; | |||
function CreateRendererOpenGL(const aContext: TtsContext): TltsRendererOpenGL; | |||
begin | |||
if not dglOpenGL.InitOpenGL then | |||
raise Exception.Create('unable to initialize OpenGL'); | |||
{$IF DEFINED(WINDOWS)} | |||
if (wglGetCurrentContext() = 0) then | |||
raise Exception.Create('no valid OpenGL context bound'); | |||
{$ELSEIF DEFINED(LINUX)} | |||
if (glXGetCurrentContext() = nil) then | |||
raise Exception.Create('no valid OpenGL context bound'); | |||
{$ENDIF} | |||
dglOpenGL.ReadOpenGLCore; | |||
// check needed functions | |||
CheckFunction(dglOpenGL.glBindBuffer, 'glBindBuffer'); | |||
CheckFunction(dglOpenGL.glBindTexture, 'glBindTexture'); | |||
CheckFunction(dglOpenGL.glBufferData, 'glBufferData'); | |||
CheckFunction(dglOpenGL.glColor4fv, 'glColor4fv'); | |||
CheckFunction(dglOpenGL.glDeleteBuffers, 'glDeleteBuffers'); | |||
CheckFunction(dglOpenGL.glDeleteTextures, 'glDeleteTextures'); | |||
CheckFunction(dglOpenGL.glDisableClientState, 'glDisableClientState'); | |||
CheckFunction(dglOpenGL.glDrawArrays, 'glDrawArrays'); | |||
CheckFunction(dglOpenGL.glEnable, 'glEnable'); | |||
CheckFunction(dglOpenGL.glEnableClientState, 'glEnableClientState'); | |||
CheckFunction(dglOpenGL.glGenBuffers, 'glGenBuffers'); | |||
CheckFunction(dglOpenGL.glGenTextures, 'glGenTextures'); | |||
CheckFunction(dglOpenGL.glLoadIdentity, 'glLoadIdentity'); | |||
CheckFunction(dglOpenGL.glMatrixMode, 'glMatrixMode'); | |||
CheckFunction(dglOpenGL.glMultMatrixf, 'glMultMatrixf'); | |||
CheckFunction(dglOpenGL.glPixelStorei, 'glPixelStorei'); | |||
CheckFunction(dglOpenGL.glPopMatrix, 'glPopMatrix'); | |||
CheckFunction(dglOpenGL.glPushMatrix, 'glPushMatrix'); | |||
CheckFunction(dglOpenGL.glTexCoordPointer, 'glTexCoordPointer'); | |||
CheckFunction(dglOpenGL.glTexImage2D, 'glTexImage2D'); | |||
CheckFunction(dglOpenGL.glTexParameteri, 'glTexParameteri'); | |||
CheckFunction(dglOpenGL.glTexSubImage2D, 'glTexSubImage2D'); | |||
CheckFunction(dglOpenGL.glTranslatef, 'glTranslatef'); | |||
CheckFunction(dglOpenGL.glVertexPointer, 'glVertexPointer'); | |||
result := TltsRendererOpenGL.Create(aContext, aFormat); | |||
end; | |||
function CreateRendererOpenGLES(const aContext: TtsContext): TltsRendererOpenGLES; | |||
begin | |||
dglOpenGLES.InitOpenGLES; | |||
dglOpenGLES.ReadOpenGLCore; | |||
dglOpenGLES.ReadExtensions; | |||
dglOpenGLES.ReadCoreVersion; | |||
dglOpenGLES.ReadImplementationProperties; | |||
result := TltsRendererOpenGLES.Create(aContext, aFormat); | |||
end; | |||
var | |||
c: TtsContext = nil; | |||
r: TtsRenderer = nil; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererCreate(Handle=%p; Type=%d; Format=%d)', [aHandle, aType, aFormat]);{$ENDIF} | |||
result := nil; | |||
if not CheckContextHandle(aHandle, c) then | |||
exit; | |||
if not ValidateFormat(aFormat) then begin | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid format', [aFormat])); | |||
exit; | |||
end; | |||
case aType of | |||
ltsRendererOpenGL: r := CreateRendererOpenGL (c); | |||
ltsRendererOpenGLES: r := CreateRendererOpenGLES(c); | |||
else | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid renderer type', [aType])); | |||
exit; | |||
end; | |||
AddReference(ltsObjTypeRenderer, r); | |||
result := r; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererCreate=%p', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererCustomCreate(aHandle: TltsContextHandle; aFormat: TtsFormat; constref aData: TltsRendererCustomData): TltsRendererHandle; stdcall; | |||
var | |||
c: TtsContext; | |||
r: TtsRenderer; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererCustomCreate(Handle=%p; Format=%d; Data=%p)', [aHandle, aFormat, @aData]);{$ENDIF} | |||
result := nil; | |||
if not CheckContextHandle(aHandle, c) then | |||
exit; | |||
if not ValidateFormat(aFormat) then begin | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid format', [aFormat])); | |||
exit; | |||
end; | |||
r := TltsRendererCustom.Create(c, aFormat, aData); | |||
AddReference(ltsObjTypeRenderer, r); | |||
result := r; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererCustomCreate=%p', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererBeginBlock(aHandle: TltsRendererHandle; aTop, aLeft, aWidth, aHeight: Integer; aFlags: TtsBlockFlags): TltsTextBlockHandle; stdcall; | |||
var | |||
r: TtsRenderer; | |||
b: TtsTextBlock; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererBeginBlock(Handle=%p; Top=%d; Left=%d; Width=%d; Height=%d; Flags=%d)', [aHandle, aTop, aLeft, aWidth, aHeight, PtrUInt(aFlags)]);{$ENDIF} | |||
result := nil; | |||
if CheckRendererHandle(aHandle, r) then begin | |||
b := r.BeginBlock(aTop, aLeft, aWidth, aHeight, aFlags); | |||
AddReference(ltsObjTypeTextBlock, b); | |||
result := b; | |||
end; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := nil; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererBeginBlock=%p', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererEndBlock(aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
var | |||
r: TtsRenderer; | |||
b: TtsTextBlock; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererEndBlock(Handle=%p; Block=%p)', [aHandle, aBlock]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckRendererHandle(aHandle, r) and CheckTextBlockHandle(aBlock, b) then begin | |||
DelReference(ltsObjTypeTextBlock, b); | |||
r.EndBlock(b); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererEndBlock=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererAbortBlock(aHandle: TltsRendererHandle; aBlock: TltsTextBlockHandle): TltsErrorCode; stdcall; | |||
var | |||
r: TtsRenderer; | |||
b: TtsTextBlock; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererAbortBlock(Handle=%p; Block=%p)', [aHandle, aBlock]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckRendererHandle(aHandle, r) and CheckTextBlockHandle(aBlock, b) then begin | |||
DelReference(ltsObjTypeTextBlock, b); | |||
r.AbortBlock(b); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererAbortBlock=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererGetTextWidthA(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PAnsiChar): Integer; stdcall; | |||
var | |||
r: TtsRenderer; | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererGetTextWidthA(Handle=%p; Font=%p; Text=%p)', [aHandle, aFont, aText]);{$ENDIF} | |||
if CheckRendererHandle(aHandle, r) and CheckFontHandle(aFont, f) | |||
then result := r.GetTextWidthA(f, aText) | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererGetTextWidthA=%d', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererGetTextWidthW(aHandle: TltsRendererHandle; aFont: TltsFontHandle; aText: PWideChar): Integer; stdcall; | |||
var | |||
r: TtsRenderer; | |||
f: TtsFont; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererGetTextWidthW(Handle=%p; Font=%p; Text=%p)', [aHandle, aFont, aText]);{$ENDIF} | |||
if CheckRendererHandle(aHandle, r) and CheckFontHandle(aFont, f) | |||
then result := r.GetTextWidthW(f, aText) | |||
else result := -1; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := -1; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererGetTextWidthW=%d', [result]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ltsRendererDestroy(aHandle: TltsRendererHandle): TltsErrorCode; stdcall; | |||
var | |||
r: TtsRenderer; | |||
begin | |||
try | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererDestroy(Handle=%p)', [aHandle]);{$ENDIF} | |||
result := ltsErrNone; | |||
if CheckRendererHandle(aHandle, r) then begin | |||
DelReference(ltsObjTypeRenderer, r); | |||
FreeAndNil(r); | |||
end else | |||
result := LastErrorCode; | |||
except | |||
on ex: Exception do begin | |||
SetLastError(ex); | |||
result := LastErrorCode; | |||
end; | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ltsRendererDestroy=%d', [Integer(result)]);{$ENDIF} | |||
end; | |||
end. | |||
@@ -1,89 +1,89 @@ | |||
unit ultsTypes; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils; | |||
type | |||
{$Z4} | |||
TltsErrorCode = ( | |||
ltsErrUnknown = -1, | |||
ltsErrNone = 0, | |||
// misc | |||
ltsErrNotInitialized = 1, | |||
ltsErrInvalidEnum = 2, | |||
ltsErrInvalidValue = 3, | |||
ltsErrInvalidOperation = 4, | |||
ltsErrInvalidType = 5, | |||
// invalid handles | |||
ltsErrInvalidContextHandle = 100, | |||
ltsErrInvalidRendererHandle = 101, | |||
ltsErrInvalidTextBlockHandle = 102, | |||
ltsErrInvalidFontHandle = 103, | |||
ltsErrInvalidFontCreatorHandle = 104, | |||
ltsErrInvalidImageHandle = 105, | |||
ltsErrInvalidPostProcHandle = 106 | |||
); | |||
{$Z4} | |||
TltsObjectType = ( | |||
ltsObjTypeUnknown, | |||
ltsObjTypeContext, | |||
ltsObjTypeRenderer, | |||
ltsObjTypeFontCreator, | |||
ltsObjTypeFont, | |||
ltsObjTypeTextBlock, | |||
ltsObjTypeImage, | |||
ltsObjTypePostProcessor, | |||
ltsObjTypeChar | |||
); | |||
{$Z4} | |||
TltsRendererType = ( | |||
ltsRendererUnknown, | |||
ltsRendererOpenGL, | |||
ltsRendererOpenGLES | |||
); | |||
{$Z4} | |||
TltsFontCreatorType = ( | |||
ltsFontCreatorUnknown, | |||
ltsFontCreatorFreeType, | |||
ltsFontCreatorGDI, | |||
ltsFontCreatorCustom | |||
); | |||
TltsHandle = Pointer; | |||
TltsContextHandle = TltsHandle; | |||
TltsRendererHandle = TltsHandle; | |||
TltsTextBlockHandle = TltsHandle; | |||
TltsFontCreatorHandle = TltsHandle; | |||
TltsFontHandle = TltsHandle; | |||
TltsPostProcessorHandle = TltsHandle; | |||
TltsImageHandle = TltsHandle; | |||
TltsCharHandle = TltsHandle; | |||
TltsStreamOrigin = ( | |||
ltsStreamOriginBegin = Integer(soBeginning), | |||
ltsStreamOriginCurrent = Integer(soCurrent), | |||
ltsStreamOriginEnd = Integer(soEnd) | |||
); | |||
TltsStreamFuncRead = function(const aArgs: Pointer; const aBuffer: Pointer; const aSize: Integer): Integer; stdcall; | |||
TltsStreamFuncSeek = function(const aArgs: Pointer; const aOrigin: TltsStreamOrigin; const aPos: Integer): Integer; stdcall; | |||
PltsStream = ^TltsStream; | |||
TltsStream = packed record | |||
args: Pointer; | |||
read: TltsStreamFuncRead; | |||
seek: TltsStreamFuncSeek; | |||
end; | |||
implementation | |||
end. | |||
unit ultsTypes; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils; | |||
type | |||
{$Z4} | |||
TltsErrorCode = ( | |||
ltsErrUnknown = -1, | |||
ltsErrNone = 0, | |||
// misc | |||
ltsErrNotInitialized = 1, | |||
ltsErrInvalidEnum = 2, | |||
ltsErrInvalidValue = 3, | |||
ltsErrInvalidOperation = 4, | |||
ltsErrInvalidType = 5, | |||
// invalid handles | |||
ltsErrInvalidContextHandle = 100, | |||
ltsErrInvalidRendererHandle = 101, | |||
ltsErrInvalidTextBlockHandle = 102, | |||
ltsErrInvalidFontHandle = 103, | |||
ltsErrInvalidFontCreatorHandle = 104, | |||
ltsErrInvalidImageHandle = 105, | |||
ltsErrInvalidPostProcHandle = 106 | |||
); | |||
{$Z4} | |||
TltsObjectType = ( | |||
ltsObjTypeUnknown, | |||
ltsObjTypeContext, | |||
ltsObjTypeRenderer, | |||
ltsObjTypeFontCreator, | |||
ltsObjTypeFont, | |||
ltsObjTypeTextBlock, | |||
ltsObjTypeImage, | |||
ltsObjTypePostProcessor, | |||
ltsObjTypeChar | |||
); | |||
{$Z4} | |||
TltsRendererType = ( | |||
ltsRendererUnknown, | |||
ltsRendererOpenGL, | |||
ltsRendererOpenGLES | |||
); | |||
{$Z4} | |||
TltsFontCreatorType = ( | |||
ltsFontCreatorUnknown, | |||
ltsFontCreatorFreeType, | |||
ltsFontCreatorGDI, | |||
ltsFontCreatorCustom | |||
); | |||
TltsHandle = Pointer; | |||
TltsContextHandle = TltsHandle; | |||
TltsRendererHandle = TltsHandle; | |||
TltsTextBlockHandle = TltsHandle; | |||
TltsFontCreatorHandle = TltsHandle; | |||
TltsFontHandle = TltsHandle; | |||
TltsPostProcessorHandle = TltsHandle; | |||
TltsImageHandle = TltsHandle; | |||
TltsCharHandle = TltsHandle; | |||
TltsStreamOrigin = ( | |||
ltsStreamOriginBegin = Integer(soBeginning), | |||
ltsStreamOriginCurrent = Integer(soCurrent), | |||
ltsStreamOriginEnd = Integer(soEnd) | |||
); | |||
TltsStreamFuncRead = function(const aArgs: Pointer; const aBuffer: Pointer; const aSize: Integer): Integer; stdcall; | |||
TltsStreamFuncSeek = function(const aArgs: Pointer; const aOrigin: TltsStreamOrigin; const aPos: Integer): Integer; stdcall; | |||
PltsStream = ^TltsStream; | |||
TltsStream = packed record | |||
args: Pointer; | |||
read: TltsStreamFuncRead; | |||
seek: TltsStreamFuncSeek; | |||
end; | |||
implementation | |||
end. | |||
@@ -1,349 +1,351 @@ | |||
unit ultsUtils; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
uutlGenerics, | |||
ultsTypes, | |||
utsTextSuite; | |||
type | |||
TtsPostProcessorClass = class of TtsPostProcessor; | |||
procedure SetLastError(const aEx: Exception); | |||
procedure SetLastError(const aErrorCode: TltsErrorCode; const aErrorMsg: String); | |||
function CheckIfInitialized: Boolean; | |||
function CheckContextHandle(const aHandle: TltsContextHandle; out aContext: TtsContext): Boolean; | |||
function CheckRendererHandle(const aHandle: TltsContextHandle; out aRenderer: TtsRenderer): Boolean; | |||
function CheckTextBlockHandle(const aHandle: TltsTextBlockHandle; out aTextBlock: TtsTextBlock): Boolean; | |||
function CheckFontHandle(const aHandle: TltsFontHandle; out aFont: TtsFont): Boolean; | |||
function CheckFontCreatorHandle(const aHandle: TltsFontCreatorHandle; out aFontCreator: TtsFontCreator): Boolean; | |||
function CheckImageHandle(const aHandle: TltsImageHandle; out aImage: TtsImage): Boolean; | |||
function CheckCharHandle(const aHandle: TltsCharHandle; out aChar: TtsChar): Boolean; | |||
function CheckPostProcessorHandle(const aHandle: TltsPostProcessorHandle; const aType: TtsPostProcessorClass; out aPostProcessor): Boolean; | |||
procedure AddReference(const aType: TltsObjectType; const aRef: TObject); | |||
procedure DelReference(const aType: TltsObjectType; const aRef: TObject); | |||
procedure DelReference(const aRef: TObject); | |||
function ValidateCodePage(const aValue: TtsCodePage): Boolean; | |||
function ValidateFormat(const aValue: TtsFormat): Boolean; | |||
function ValidateCharRangeUsage(const aValue: TtsCharRangeUsage): Boolean; | |||
procedure Initialize; | |||
procedure Finalize; | |||
type | |||
TltsStreamImpl = class(TStream) | |||
private | |||
fStream: PltsStream; | |||
public | |||
function Read(var Buffer; Count: Longint): Longint; override; | |||
function Seek(Offset: Longint; Origin: Word): Longint; override; overload; | |||
constructor Create(const aStream: PltsStream); | |||
end; | |||
var | |||
LastErrorCode: TltsErrorCode = ltsErrNone; | |||
LastErrorMsg: String; | |||
implementation | |||
{$IFDEF DUMP_HEAPTRACE} | |||
uses | |||
heaptrc; | |||
{$ENDIF} | |||
type | |||
TtsContextHashSet = specialize TutlHashSet<TtsContext>; | |||
TtsRendererHashSet = specialize TutlHashSet<TtsRenderer>; | |||
TtsTextBlockHashSet = specialize TutlHashSet<TtsTextBlock>; | |||
TtsFontHashSet = specialize TutlHashSet<TtsFont>; | |||
TtsFontCreatorHashSet = specialize TutlHashSet<TtsFontCreator>; | |||
TtsImageHashSet = specialize TutlHashSet<TtsImage>; | |||
TtsPostProcessorHashSet = specialize TutlHashSet<TtsPostProcessor>; | |||
TtsCharHashSet = specialize TutlHashSet<TtsChar>; | |||
var | |||
IsInitilized: Boolean = false; | |||
Contexts: TtsContextHashSet = nil; | |||
Renderers: TtsRendererHashSet = nil; | |||
TextBlocks: TtsTextBlockHashSet = nil; | |||
Fonts: TtsFontHashSet = nil; | |||
FontCreators: TtsFontCreatorHashSet = nil; | |||
Images: TtsImageHashSet = nil; | |||
PostProcessors: TtsPostProcessorHashSet = nil; | |||
Chars: TtsCharHashSet = nil; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure SetLastError(const aEx: Exception); | |||
begin | |||
LastErrorCode := ltsErrUnknown; | |||
LastErrorMsg := aEx.Message; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure SetLastError(const aErrorCode: TltsErrorCode; const aErrorMsg: String); | |||
begin | |||
LastErrorCode := aErrorCode; | |||
LastErrorMsg := aErrorMsg; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckIfInitialized: Boolean; | |||
begin | |||
result := IsInitilized; | |||
if not result then | |||
SetLastError(ltsErrNotInitialized, 'libTextSuite has not been initialized. call ltsInitialize before using any other methods.'); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckContextHandle(const aHandle: TltsContextHandle; out aContext: TtsContext): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aContext := TtsContext(aHandle); | |||
result := Contexts.Contains(aContext); | |||
if not result then | |||
SetLastError(ltsErrInvalidContextHandle, Format('0x%.16x is not a valid context handle', [{%H-}PtrUInt(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckRendererHandle(const aHandle: TltsContextHandle; out aRenderer: TtsRenderer): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aRenderer := TtsRenderer(aHandle); | |||
result := Renderers.Contains(aRenderer); | |||
if not result then | |||
SetLastError(ltsErrInvalidRendererHandle, Format('0x%.16x is not a valid renderer handle', [{%H-}PtrUInt(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckTextBlockHandle(const aHandle: TltsTextBlockHandle; out aTextBlock: TtsTextBlock): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aTextBlock := TtsTextBlock(aHandle); | |||
result := TextBlocks.Contains(aTextBlock); | |||
if not result then | |||
SetLastError(ltsErrInvalidTextBlockHandle, Format('0x%.16x is no a valid text block handle', [{%H-}PtrUInt(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckFontHandle(const aHandle: TltsFontHandle; out aFont: TtsFont): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aFont := TtsFont(aHandle); | |||
result := Fonts.Contains(aFont); | |||
if not result then | |||
SetLastError(ltsErrInvalidFontHandle, Format('0x%.16x is no a valid font handle', [{%H-}PtrUInt(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckFontCreatorHandle(const aHandle: TltsFontCreatorHandle; out aFontCreator: TtsFontCreator): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aFontCreator := TtsFontCreator(aHandle); | |||
result := FontCreators.Contains(aFontCreator); | |||
if not result then | |||
SetLastError(ltsErrInvalidFontCreatorHandle, Format('0x%.16x is no a valid font creator handle', [{%H-}PtrUInt(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckImageHandle(const aHandle: TltsImageHandle; out aImage: TtsImage): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aImage := TtsImage(aHandle); | |||
result := Images.Contains(aImage); | |||
if not result then | |||
SetLastError(ltsErrInvalidImageHandle, Format('0x%.16x is no a valid image handle', [{%H-}PtrUInt(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckCharHandle(const aHandle: TltsCharHandle; out aChar: TtsChar): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aChar := TtsChar(aHandle); | |||
result := Chars.Contains(aChar); | |||
if not result then | |||
SetLastError(ltsErrInvalidImageHandle, Format('0x%.16x is no a valid char handle', [{%H-}PtrUInt(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckPostProcessorHandle(const aHandle: TltsPostProcessorHandle; const aType: TtsPostProcessorClass; out aPostProcessor): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
TtsPostProcessor(aPostProcessor) := TtsPostProcessor(aHandle); | |||
result := PostProcessors.Contains(TtsPostProcessor(aPostProcessor)); | |||
if not result then begin | |||
SetLastError(ltsErrInvalidPostProcHandle, Format('0x%.16x is no a valid image handle', [{%H-}PtrUInt(aHandle)])); | |||
exit; | |||
end; | |||
result := (TtsPostProcessor(aPostProcessor) is aType); | |||
if not result then begin | |||
SetLastError(ltsErrInvalidType, Format('0x%.16x is no a %s post processor', [{%H-}PtrUInt(aHandle), aType.ClassName])); | |||
exit; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure AddReference(const aType: TltsObjectType; const aRef: TObject); | |||
begin | |||
case aType of | |||
ltsObjTypeContext: Contexts.Add(aRef as TtsContext); | |||
ltsObjTypeRenderer: Renderers.Add(aRef as TtsRenderer); | |||
ltsObjTypeFont: Fonts.Add(aRef as TtsFont); | |||
ltsObjTypeTextBlock: TextBlocks.Add(aRef as TtsTextBlock); | |||
ltsObjTypeFontCreator: FontCreators.Add(aRef as TtsFontCreator); | |||
ltsObjTypeImage: Images.Add(aRef as TtsImage); | |||
ltsObjTypePostProcessor: PostProcessors.Add(aRef as TtsPostProcessor); | |||
ltsObjTypeChar: Chars.Add(aRef as TtsChar); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure DelReference(const aType: TltsObjectType; const aRef: TObject); | |||
begin | |||
case aType of | |||
ltsObjTypeContext: Contexts.Remove(aRef as TtsContext); | |||
ltsObjTypeRenderer: Renderers.Remove(aRef as TtsRenderer); | |||
ltsObjTypeFont: Fonts.Remove(aRef as TtsFont); | |||
ltsObjTypeTextBlock: TextBlocks.Remove(aRef as TtsTextBlock); | |||
ltsObjTypeFontCreator: FontCreators.Remove(aRef as TtsFontCreator); | |||
ltsObjTypeImage: Images.Remove(aRef as TtsImage); | |||
ltsObjTypePostProcessor: PostProcessors.Remove(aRef as TtsPostProcessor); | |||
ltsObjTypeChar: Chars.Remove(aRef as TtsChar); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure DelReference(const aRef: TObject); | |||
begin | |||
if (aRef is TtsRenderer) then | |||
DelReference(ltsObjTypeRenderer, aRef) | |||
else if (aRef is TtsTextBlock) then | |||
DelReference(ltsObjTypeTextBlock, aRef) | |||
else if (aRef is TtsFont) then | |||
DelReference(ltsObjTypeFont, aRef) | |||
else if (aRef is TtsContext) then | |||
DelReference(ltsObjTypeContext, aRef) | |||
else if (aRef is TtsFontCreator) then | |||
DelReference(ltsObjTypeFontCreator, aRef) | |||
else if (aRef is TtsImage) then | |||
DelReference(ltsObjTypeImage, aRef) | |||
else if (aRef is TtsPostProcessor) then | |||
DelReference(ltsObjTypePostProcessor, aRef) | |||
else if (aRef is TtsChar) then | |||
DelReference(ltsObjTypeChar, aRef); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ValidateCodePage(const aValue: TtsCodePage): Boolean; | |||
begin | |||
result := (aValue >= Low(TtsCodePage)) and (aValue <= High(TtsCodePage)); | |||
if not result then | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid code page value', [aValue])); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ValidateFormat(const aValue: TtsFormat): Boolean; | |||
begin | |||
result := (aValue >= Low(TtsFormat)) and (aValue <= High(TtsFormat)); | |||
if not result then | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid format value', [aValue])); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ValidateCharRangeUsage(const aValue: TtsCharRangeUsage): Boolean; | |||
begin | |||
result := (aValue >= Low(TtsCharRangeUsage)) and (aValue <= High(TtsCharRangeUsage)); | |||
if not result then | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid char range usage value', [aValue])); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure Initialize; | |||
{$IFDEF DUMP_HEAPTRACE} | |||
var | |||
heaptrcFile: String; | |||
{$ENDIF} | |||
begin | |||
{$IFDEF DUMP_HEAPTRACE} | |||
heaptrcFile := ChangeFileExt(ParamStr(0), '.libTextSuite.heaptrc'); | |||
if (FileExists(heaptrcFile)) then | |||
DeleteFile(heaptrcFile); | |||
SetHeapTraceOutput(heaptrcFile); | |||
{$ENDIF} | |||
Contexts := TtsContextHashSet.Create(true); | |||
Renderers := TtsRendererHashSet.Create(false); | |||
TextBlocks := TtsTextBlockHashSet.Create(false); | |||
FontCreators := TtsFontCreatorHashSet.Create(false); | |||
Fonts := TtsFontHashSet.Create(false); | |||
Images := TtsImageHashSet.Create(false); | |||
PostProcessors := TtsPostProcessorHashSet.Create(false); | |||
Chars := TtsCharHashSet.Create(false); | |||
IsInitilized := true; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure Finalize; | |||
begin | |||
IsInitilized := false; | |||
FreeAndNil(Chars); | |||
FreeAndNil(PostProcessors); | |||
FreeAndNil(Images); | |||
FreeAndNil(TextBlocks); | |||
FreeAndNil(Fonts); | |||
FreeAndNil(FontCreators); | |||
FreeAndNil(Renderers); | |||
FreeAndNil(Contexts); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsStreamImpl//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsStreamImpl.Read(var Buffer; Count: Longint): Longint; | |||
begin | |||
if not Assigned(fStream) or not Assigned(fStream^.read) | |||
then result := inherited Read(Buffer, Count) | |||
else result := fStream^.read(fStream^.args, @buffer, Count); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsStreamImpl.Seek(Offset: Longint; Origin: Word): Longint; | |||
begin | |||
if not Assigned(fStream) or not Assigned(fStream^.seek) | |||
then result := inherited Seek(Offset, Origin) | |||
else result := fStream^.seek(fStream^.args, TltsStreamOrigin(Origin), Offset); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsStreamImpl.Create(const aStream: PltsStream); | |||
begin | |||
inherited Create; | |||
fStream := aStream; | |||
end; | |||
end. | |||
unit ultsUtils; | |||
{$mode objfpc}{$H+} | |||
interface | |||
uses | |||
Classes, SysUtils, | |||
uutlGenerics, | |||
ultsTypes, | |||
utsTextSuite | |||
{$IFDEF DUMP_HEAPTRACE}, heaptrc{$ENDIF} | |||
{$IFDEF DEBUG}, uutlLogger{$ENDIF} | |||
; | |||
type | |||
TtsPostProcessorClass = class of TtsPostProcessor; | |||
procedure SetLastError(const aEx: Exception); | |||
procedure SetLastError(const aErrorCode: TltsErrorCode; const aErrorMsg: String); | |||
function CheckIfInitialized: Boolean; | |||
function CheckContextHandle(const aHandle: TltsContextHandle; out aContext: TtsContext): Boolean; | |||
function CheckRendererHandle(const aHandle: TltsContextHandle; out aRenderer: TtsRenderer): Boolean; | |||
function CheckTextBlockHandle(const aHandle: TltsTextBlockHandle; out aTextBlock: TtsTextBlock): Boolean; | |||
function CheckFontHandle(const aHandle: TltsFontHandle; out aFont: TtsFont): Boolean; | |||
function CheckFontCreatorHandle(const aHandle: TltsFontCreatorHandle; out aFontCreator: TtsFontCreator): Boolean; | |||
function CheckImageHandle(const aHandle: TltsImageHandle; out aImage: TtsImage): Boolean; | |||
function CheckCharHandle(const aHandle: TltsCharHandle; out aChar: TtsChar): Boolean; | |||
function CheckPostProcessorHandle(const aHandle: TltsPostProcessorHandle; const aType: TtsPostProcessorClass; out aPostProcessor): Boolean; | |||
procedure AddReference(const aType: TltsObjectType; const aRef: TObject); | |||
procedure DelReference(const aType: TltsObjectType; const aRef: TObject); | |||
procedure DelReference(const aRef: TObject); | |||
function ValidateCodePage(const aValue: TtsCodePage): Boolean; | |||
function ValidateFormat(const aValue: TtsFormat): Boolean; | |||
function ValidateCharRangeUsage(const aValue: TtsCharRangeUsage): Boolean; | |||
procedure Initialize; | |||
procedure Finalize; | |||
type | |||
TltsStreamImpl = class(TStream) | |||
private | |||
fStream: PltsStream; | |||
public | |||
function Read(var Buffer; Count: Longint): Longint; override; | |||
function Seek(Offset: Longint; Origin: Word): Longint; override; overload; | |||
constructor Create(const aStream: PltsStream); | |||
end; | |||
var | |||
LastErrorCode: TltsErrorCode = ltsErrNone; | |||
LastErrorMsg: String; | |||
implementation | |||
type | |||
TtsContextHashSet = specialize TutlHashSet<TtsContext>; | |||
TtsRendererHashSet = specialize TutlHashSet<TtsRenderer>; | |||
TtsTextBlockHashSet = specialize TutlHashSet<TtsTextBlock>; | |||
TtsFontHashSet = specialize TutlHashSet<TtsFont>; | |||
TtsFontCreatorHashSet = specialize TutlHashSet<TtsFontCreator>; | |||
TtsImageHashSet = specialize TutlHashSet<TtsImage>; | |||
TtsPostProcessorHashSet = specialize TutlHashSet<TtsPostProcessor>; | |||
TtsCharHashSet = specialize TutlHashSet<TtsChar>; | |||
var | |||
IsInitilized: Boolean = false; | |||
Contexts: TtsContextHashSet = nil; | |||
Renderers: TtsRendererHashSet = nil; | |||
TextBlocks: TtsTextBlockHashSet = nil; | |||
Fonts: TtsFontHashSet = nil; | |||
FontCreators: TtsFontCreatorHashSet = nil; | |||
Images: TtsImageHashSet = nil; | |||
PostProcessors: TtsPostProcessorHashSet = nil; | |||
Chars: TtsCharHashSet = nil; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure SetLastError(const aEx: Exception); | |||
begin | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'SetLastError(Error=%d; Message=%s)', [Integer(ltsErrUnknown), aEx.Message]);{$ENDIF} | |||
LastErrorCode := ltsErrUnknown; | |||
LastErrorMsg := aEx.Message; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure SetLastError(const aErrorCode: TltsErrorCode; const aErrorMsg: String); | |||
begin | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'SetLastError(Error=%d; Message=%s)', [Integer(aErrorCode), aErrorMsg]);{$ENDIF} | |||
LastErrorCode := aErrorCode; | |||
LastErrorMsg := aErrorMsg; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckIfInitialized: Boolean; | |||
begin | |||
result := IsInitilized; | |||
if not result then | |||
SetLastError(ltsErrNotInitialized, 'libTextSuite has not been initialized. call ltsInitialize before using any other methods.'); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckContextHandle(const aHandle: TltsContextHandle; out aContext: TtsContext): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aContext := TtsContext(aHandle); | |||
result := Contexts.Contains(aContext); | |||
if not result then | |||
SetLastError(ltsErrInvalidContextHandle, Format('0x%p is not a valid context handle', [Pointer(aHandle)])); | |||
end; | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'CheckContextHandle(result=%d)', [Byte(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckRendererHandle(const aHandle: TltsContextHandle; out aRenderer: TtsRenderer): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aRenderer := TtsRenderer(aHandle); | |||
result := Renderers.Contains(aRenderer); | |||
if not result then | |||
SetLastError(ltsErrInvalidRendererHandle, Format('0x%p is not a valid renderer handle', [Pointer(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckTextBlockHandle(const aHandle: TltsTextBlockHandle; out aTextBlock: TtsTextBlock): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aTextBlock := TtsTextBlock(aHandle); | |||
result := TextBlocks.Contains(aTextBlock); | |||
if not result then | |||
SetLastError(ltsErrInvalidTextBlockHandle, Format('0x%p is no a valid text block handle', [Pointer(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckFontHandle(const aHandle: TltsFontHandle; out aFont: TtsFont): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aFont := TtsFont(aHandle); | |||
result := Fonts.Contains(aFont); | |||
if not result then | |||
SetLastError(ltsErrInvalidFontHandle, Format('0x%p is no a valid font handle', [Pointer(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckFontCreatorHandle(const aHandle: TltsFontCreatorHandle; out aFontCreator: TtsFontCreator): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aFontCreator := TtsFontCreator(aHandle); | |||
result := FontCreators.Contains(aFontCreator); | |||
if not result then | |||
SetLastError(ltsErrInvalidFontCreatorHandle, Format('0x%p is no a valid font creator handle', [Pointer(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckImageHandle(const aHandle: TltsImageHandle; out aImage: TtsImage): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aImage := TtsImage(aHandle); | |||
result := Images.Contains(aImage); | |||
if not result then | |||
SetLastError(ltsErrInvalidImageHandle, Format('0x%p is no a valid image handle', [Pointer(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckCharHandle(const aHandle: TltsCharHandle; out aChar: TtsChar): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
aChar := TtsChar(aHandle); | |||
result := Chars.Contains(aChar); | |||
if not result then | |||
SetLastError(ltsErrInvalidImageHandle, Format('0x%p is no a valid char handle', [Pointer(aHandle)])); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function CheckPostProcessorHandle(const aHandle: TltsPostProcessorHandle; const aType: TtsPostProcessorClass; out aPostProcessor): Boolean; | |||
begin | |||
result := CheckIfInitialized; | |||
if result then begin | |||
TtsPostProcessor(aPostProcessor) := TtsPostProcessor(aHandle); | |||
result := PostProcessors.Contains(TtsPostProcessor(aPostProcessor)); | |||
if not result then begin | |||
SetLastError(ltsErrInvalidPostProcHandle, Format('0x%p is no a valid post processor handle', [Pointer(aHandle)])); | |||
exit; | |||
end; | |||
result := (TtsPostProcessor(aPostProcessor) is aType); | |||
if not result then begin | |||
SetLastError(ltsErrInvalidType, Format('0x%p is no a %s post processor', [Pointer(aHandle), aType.ClassName])); | |||
exit; | |||
end; | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure AddReference(const aType: TltsObjectType; const aRef: TObject); | |||
begin | |||
case aType of | |||
ltsObjTypeContext: Contexts.Add(aRef as TtsContext); | |||
ltsObjTypeRenderer: Renderers.Add(aRef as TtsRenderer); | |||
ltsObjTypeFont: Fonts.Add(aRef as TtsFont); | |||
ltsObjTypeTextBlock: TextBlocks.Add(aRef as TtsTextBlock); | |||
ltsObjTypeFontCreator: FontCreators.Add(aRef as TtsFontCreator); | |||
ltsObjTypeImage: Images.Add(aRef as TtsImage); | |||
ltsObjTypePostProcessor: PostProcessors.Add(aRef as TtsPostProcessor); | |||
ltsObjTypeChar: Chars.Add(aRef as TtsChar); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure DelReference(const aType: TltsObjectType; const aRef: TObject); | |||
begin | |||
case aType of | |||
ltsObjTypeContext: Contexts.Remove(aRef as TtsContext); | |||
ltsObjTypeRenderer: Renderers.Remove(aRef as TtsRenderer); | |||
ltsObjTypeFont: Fonts.Remove(aRef as TtsFont); | |||
ltsObjTypeTextBlock: TextBlocks.Remove(aRef as TtsTextBlock); | |||
ltsObjTypeFontCreator: FontCreators.Remove(aRef as TtsFontCreator); | |||
ltsObjTypeImage: Images.Remove(aRef as TtsImage); | |||
ltsObjTypePostProcessor: PostProcessors.Remove(aRef as TtsPostProcessor); | |||
ltsObjTypeChar: Chars.Remove(aRef as TtsChar); | |||
end; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure DelReference(const aRef: TObject); | |||
begin | |||
if (aRef is TtsRenderer) then | |||
DelReference(ltsObjTypeRenderer, aRef) | |||
else if (aRef is TtsTextBlock) then | |||
DelReference(ltsObjTypeTextBlock, aRef) | |||
else if (aRef is TtsFont) then | |||
DelReference(ltsObjTypeFont, aRef) | |||
else if (aRef is TtsContext) then | |||
DelReference(ltsObjTypeContext, aRef) | |||
else if (aRef is TtsFontCreator) then | |||
DelReference(ltsObjTypeFontCreator, aRef) | |||
else if (aRef is TtsImage) then | |||
DelReference(ltsObjTypeImage, aRef) | |||
else if (aRef is TtsPostProcessor) then | |||
DelReference(ltsObjTypePostProcessor, aRef) | |||
else if (aRef is TtsChar) then | |||
DelReference(ltsObjTypeChar, aRef); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ValidateCodePage(const aValue: TtsCodePage): Boolean; | |||
begin | |||
result := (aValue >= Low(TtsCodePage)) and (aValue <= High(TtsCodePage)); | |||
if not result then | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid code page value', [aValue])); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ValidateFormat(const aValue: TtsFormat): Boolean; | |||
begin | |||
result := (aValue >= Low(TtsFormat)) and (aValue <= High(TtsFormat)); | |||
if not result then | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid format value', [aValue])); | |||
{$IFDEF DEBUG}utlLogger.Log(nil, 'ValidateFormat(result=%d)', [Byte(result)]);{$ENDIF} | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function ValidateCharRangeUsage(const aValue: TtsCharRangeUsage): Boolean; | |||
begin | |||
result := (aValue >= Low(TtsCharRangeUsage)) and (aValue <= High(TtsCharRangeUsage)); | |||
if not result then | |||
SetLastError(ltsErrInvalidEnum, Format('%d is not a valid char range usage value', [aValue])); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure Initialize; | |||
{$IFDEF DUMP_HEAPTRACE} | |||
var | |||
heaptrcFile: String; | |||
{$ENDIF} | |||
begin | |||
{$IFDEF DUMP_HEAPTRACE} | |||
heaptrcFile := ChangeFileExt(ParamStr(0), '.libTextSuite.heaptrc'); | |||
if (FileExists(heaptrcFile)) then | |||
DeleteFile(heaptrcFile); | |||
SetHeapTraceOutput(heaptrcFile); | |||
{$ENDIF} | |||
Contexts := TtsContextHashSet.Create(true); | |||
Renderers := TtsRendererHashSet.Create(false); | |||
TextBlocks := TtsTextBlockHashSet.Create(false); | |||
FontCreators := TtsFontCreatorHashSet.Create(false); | |||
Fonts := TtsFontHashSet.Create(false); | |||
Images := TtsImageHashSet.Create(false); | |||
PostProcessors := TtsPostProcessorHashSet.Create(false); | |||
Chars := TtsCharHashSet.Create(false); | |||
IsInitilized := true; | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
procedure Finalize; | |||
begin | |||
IsInitilized := false; | |||
FreeAndNil(Chars); | |||
FreeAndNil(PostProcessors); | |||
FreeAndNil(Images); | |||
FreeAndNil(TextBlocks); | |||
FreeAndNil(Fonts); | |||
FreeAndNil(FontCreators); | |||
FreeAndNil(Renderers); | |||
FreeAndNil(Contexts); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//TltsStreamImpl//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsStreamImpl.Read(var Buffer; Count: Longint): Longint; | |||
begin | |||
if not Assigned(fStream) or not Assigned(fStream^.read) | |||
then result := inherited Read(Buffer, Count) | |||
else result := fStream^.read(fStream^.args, @buffer, Count); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
function TltsStreamImpl.Seek(Offset: Longint; Origin: Word): Longint; | |||
begin | |||
if not Assigned(fStream) or not Assigned(fStream^.seek) | |||
then result := inherited Seek(Offset, Origin) | |||
else result := fStream^.seek(fStream^.args, TltsStreamOrigin(Origin), Offset); | |||
end; | |||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
constructor TltsStreamImpl.Create(const aStream: PltsStream); | |||
begin | |||
inherited Create; | |||
fStream := aStream; | |||
end; | |||
end. | |||