@@ -6,25 +6,27 @@
#include "..\..\libTextSuite.hpp"
#if _WIN64
# define LIB_NAME "..\\..\\..\\libTextSuite-x86_64-win64.dll"
static const std::string LibName("..\\..\\..\\libTextSuite-x86_64-win64.dll");
#elif _WIN32
# define LIB_NAME "..\\..\\..\\libTextSuite-i386-win32.dll"
static const std::string LibName("..\\..\\..\\libTextSuite-i386-win32.dll");
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__)
# define LIB_NAME "../../../libTextSuite-x86_64-linux.so"
static const std::string LibName("../../../libTextSuite-x86_64-linux.so");
#elif __linux__ && (__i386 || _X86_)
# define LIB_NAME "../../../libTextSuite-i386-linux.so"
static const std::string LibName("../../../libTextSuite-i386-linux.so");
#else
# error 'unknown operation system'
#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;
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 wchar_t CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 };
@@ -37,133 +39,78 @@ const uint8_t PATTER_DATA[] = {
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, ltsFontCreatorGDI);
if (!creator)
{
showMessage("unable to create text suite creator");
return false;
}
{
library.reset(new lts::Library(LibName));
context.reset(new lts::Context(*library));
creator.reset(new lts::FontCreatorGDI(*context));
renderer.reset(new lts::RendererOpenGL(*context, lts::Format::RGBA8));
ppList.reset(new lts::PostProcessorList<PostProcessorPtrU>(*context));
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;
}
pattern.reset(new lts::Image(*context));
pattern->createEmpty(lts::Format::Alpha8, 4, 4);
memcpy(pattern->getData(), &PATTER_DATA[0], 16);
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]);
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));
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]);
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));
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]);
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 = 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;
}
font = creator->getFontByFile(
"../Prototype.ttf",
40,
lts::FontStyles(),
lts::AntiAliasing::Normal);
font->setPostProcessor(ppList.get());
return true;*/
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);
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;*/
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();*/
{
font.reset();
ppList.reset();
pattern.reset();
renderer.reset();
creator.reset();
context.reset();
library.reset();
}