您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

2319 行
97 KiB

  1. #ifndef LIB_TEXT_SUITE_HPP
  2. #define LIB_TEXT_SUITE_HPP
  3. #include <list>
  4. #include <memory>
  5. #include <istream>
  6. #include <string>
  7. #include <stdint.h>
  8. #include <initializer_list>
  9. #if defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64)
  10. # define LTS_WINDOWS
  11. # include <windows.h>
  12. #elif LINUX || __linux__
  13. # define LTS_LINUX
  14. # include <dlfcn.h>
  15. #else
  16. # error "unknown operation system"
  17. #endif
  18. #if __MINGW32__
  19. # define WINAPI __stdcall
  20. #else
  21. # define WINAPI
  22. #endif
  23. /**********************************************************************************************************************************/
  24. /* public interface */
  25. /**********************************************************************************************************************************/
  26. namespace lts
  27. {
  28. /* simple types *******************************************************************************************************************/
  29. typedef wchar_t WideChar;
  30. typedef void* RenderRef;
  31. typedef void* Handle;
  32. typedef Handle ContextHandle;
  33. typedef Handle RendererHandle;
  34. typedef Handle TextBlockHandle;
  35. typedef Handle FontCreatorHandle;
  36. typedef Handle FontHandle;
  37. typedef Handle PostProcessorHandle;
  38. typedef Handle ImageHandle;
  39. typedef Handle CharHandle;
  40. /* enumerations *******************************************************************************************************************/
  41. enum class ErrorCode : int32_t
  42. {
  43. Unknown = -1,
  44. None = 0,
  45. // misc
  46. NotInitialized = 1,
  47. InvalidEnum = 2,
  48. InvalidValue = 3,
  49. InvalidOperation = 4,
  50. InvalidType = 5,
  51. // invalid handles
  52. InvalidContextHandle = 100,
  53. InvalidRendererHandle = 101,
  54. InvalidTextBlockHandle = 102,
  55. InvalidFontHandle = 103,
  56. InvalidFontCreatorHandle = 104,
  57. InvalidImageHandle = 105,
  58. InvalidPostProcHandle = 106,
  59. // library
  60. InvalidLibName = 200,
  61. InvalidLibHandle = 201,
  62. InvalidMethodName = 202
  63. };
  64. static_assert(sizeof(ErrorCode) == 4, "size of lts::ErrorCode should be 4");
  65. enum class CodePage : uint32_t
  66. {
  67. cpUTF8,
  68. cpISO_8859_1,
  69. cpISO_8859_2,
  70. cpISO_8859_3,
  71. cpISO_8859_4,
  72. cpISO_8859_5,
  73. cpISO_8859_6,
  74. cpISO_8859_7,
  75. cpISO_8859_8,
  76. cpISO_8859_9,
  77. cpISO_8859_10,
  78. cpISO_8859_11,
  79. cpISO_8859_13,
  80. cpISO_8859_14,
  81. cpISO_8859_15,
  82. cpISO_8859_16,
  83. cpISO_037,
  84. cpISO_437,
  85. cpISO_500,
  86. cpISO_737,
  87. cpISO_775,
  88. cpISO_850,
  89. cpISO_852,
  90. cpISO_855,
  91. cpISO_857,
  92. cpISO_860,
  93. cpISO_861,
  94. cpISO_862,
  95. cpISO_863,
  96. cpISO_864,
  97. cpISO_865,
  98. cpISO_866,
  99. cpISO_869,
  100. cpISO_874,
  101. cpISO_875,
  102. cpISO_1026,
  103. cpISO_1250,
  104. cpISO_1251,
  105. cpISO_1252,
  106. cpISO_1253,
  107. cpISO_1254,
  108. cpISO_1255,
  109. cpISO_1256,
  110. cpISO_1257,
  111. cpISO_1258
  112. };
  113. static_assert(sizeof(CodePage) == 4, "size of lts::CodePage should be 4");
  114. enum class Format : uint32_t
  115. {
  116. Empty,
  117. RGBA8,
  118. LumAlpha8,
  119. Alpha8,
  120. Lum8
  121. };
  122. static_assert(sizeof(Format) == 4, "size of lts::Format should be 4");
  123. enum class RendererType : uint32_t
  124. {
  125. Unknown,
  126. OpenGL,
  127. OpenGLES
  128. };
  129. static_assert(sizeof(RendererType) == 4, "size of lts::RendererType should be 4");
  130. enum class FontCreatorType : uint32_t
  131. {
  132. Unknown,
  133. FreeType,
  134. GDI,
  135. Custom
  136. };
  137. static_assert(sizeof(FontCreatorType) == 4, "size of lts::FontCreatorType should be 4");
  138. enum class VertAlign : uint32_t
  139. {
  140. Top,
  141. Center,
  142. Bottom
  143. };
  144. static_assert(sizeof(VertAlign) == 4, "size of lts::VertAlign should be 4");
  145. enum class HorzAlign : uint32_t
  146. {
  147. Left,
  148. Center,
  149. Right,
  150. Justify
  151. };
  152. static_assert(sizeof(HorzAlign) == 4, "size of lts::HorzAlign should be 4");
  153. enum class Clipping : uint32_t
  154. {
  155. None,
  156. WordBorder,
  157. CharBorder,
  158. WordComplete,
  159. CharComplete
  160. };
  161. static_assert(sizeof(Clipping) == 4, "size of lts::Clipping should be 4");
  162. enum class AntiAliasing : uint32_t
  163. {
  164. None,
  165. Normal
  166. };
  167. static_assert(sizeof(AntiAliasing) == 4, "size of lts::AntiAliasing should be 4");
  168. enum class CharRangeUsage : uint32_t
  169. {
  170. Include,
  171. Exclude
  172. };
  173. static_assert(sizeof(CharRangeUsage) == 4, "size of lts::CharRangeUsage should be 4");
  174. enum class ImageMode : uint32_t
  175. {
  176. Ignore,
  177. Replace,
  178. Modulate
  179. };
  180. static_assert(sizeof(ImageMode) == 4, "size of lts::ImageMode should be 4");
  181. enum class StreamOrigin : uint32_t
  182. {
  183. Begin = 0,
  184. Current = 1,
  185. End = 2
  186. };
  187. static_assert(sizeof(StreamOrigin) == 4, "size of lts::StreamOrigin should be 4");
  188. /* flags **************************************************************************************************************************/
  189. template <typename TEnum, typename TBase>
  190. class Flags
  191. {
  192. private:
  193. TBase _value;
  194. public:
  195. inline operator TBase() const
  196. { return _value; };
  197. inline bool isSet(const TEnum& e) const
  198. { return (_value & (1 << static_cast<TBase>(e))); };
  199. inline void set(const TEnum& e)
  200. { _value |= (1 << static_cast<TBase>(e)); };
  201. inline void unset(const TEnum& e)
  202. { _value &= ~(1 << static_cast<TBase>(e)); };
  203. inline void clear()
  204. { _value = 0; };
  205. Flags() :
  206. _value(0)
  207. { };
  208. explicit Flags(TBase value) :
  209. _value(value)
  210. { };
  211. Flags(const TEnum& e) :
  212. _value(1 << static_cast<TBase>(e))
  213. { };
  214. Flags(const Flags& f) :
  215. _value(f._value)
  216. { };
  217. Flags(const std::initializer_list<TEnum>& vec) :
  218. _value(0)
  219. {
  220. for (const auto& e : vec)
  221. set(e);
  222. };
  223. template <typename T>
  224. Flags(T begIt, T endIt) :
  225. _value(0)
  226. {
  227. for (auto i = begIt; i != endIt; ++i)
  228. set(*i);
  229. };
  230. };
  231. enum class BlockFlag
  232. {
  233. WordWrap
  234. };
  235. typedef Flags<BlockFlag, uint32_t> BlockFlags;
  236. static_assert(sizeof(BlockFlag) == 4, "size of lts::BlockFlag should be 4");
  237. static_assert(sizeof(BlockFlags) == 4, "size of lts::BlockFlags should be 4");
  238. enum class FontStyle
  239. {
  240. Bold,
  241. Italic,
  242. Underline,
  243. Strikeout,
  244. };
  245. typedef Flags<FontStyle, uint32_t> FontStyles;
  246. static_assert(sizeof(FontStyle) == 4, "size of lts::FontStyle should be 4");
  247. static_assert(sizeof(FontStyles) == 4, "size of lts::FontStyles should be 4");
  248. enum class ColorChannel
  249. {
  250. Red,
  251. Green,
  252. Blue,
  253. Alpha
  254. };
  255. typedef Flags<ColorChannel, uint32_t> ColorChannels;
  256. static_assert(sizeof(ColorChannel) == 4, "size of lts::ColorChannel should be 4");
  257. static_assert(sizeof(ColorChannels) == 4, "size of lts::ColorChannels should be 4");
  258. /* structures *********************************************************************************************************************/
  259. struct Position
  260. {
  261. int x;
  262. int y;
  263. };
  264. static_assert(sizeof(Position) == 8, "size of lts::Position should be 8");
  265. union Rect
  266. {
  267. struct { Position top_left, bottom_right; };
  268. struct { int32_t left, top, right, bottom; };
  269. };
  270. static_assert(sizeof(Rect) == 16, "size of lts::Rect should be 16");
  271. union Color4f
  272. {
  273. struct { float r, g, b, a; };
  274. float arr[4];
  275. };
  276. static_assert(sizeof(Color4f) == 16, "size of lts::Color4f should be 16");
  277. union ImageModes
  278. {
  279. struct { ImageMode r, g, b, a; };
  280. ImageMode arr[4];
  281. };
  282. static_assert(sizeof(ImageModes) == 16, "size of lts::ImageModes should be 16");
  283. struct GlyphMetric
  284. {
  285. Position glyphOrigin;
  286. Rect glyphRect;
  287. int32_t advance;
  288. };
  289. static_assert(sizeof(GlyphMetric) == 28, "size of lts::GlyphMetric should be 28");
  290. struct TextMetric
  291. {
  292. int32_t ascent;
  293. int32_t descent;
  294. int32_t externalLeading;
  295. int32_t baseLineOffset;
  296. int32_t charSpacing;
  297. int32_t lineHeight;
  298. int32_t lineSpacing;
  299. };
  300. static_assert(sizeof(TextMetric) == 28, "size of lts::TextMetric should be 28");
  301. struct FontMetric
  302. {
  303. int32_t size;
  304. FontStyles styles;
  305. AntiAliasing antiAliasing;
  306. WideChar defaultChar;
  307. uint8_t __reserved[2];
  308. int32_t ascent;
  309. int32_t descent;
  310. int32_t externalLeading;
  311. int32_t baseLineOffset;
  312. int32_t underlinePos;
  313. int32_t underlineSize;
  314. int32_t strikeoutPos;
  315. int32_t strikeoutSize;
  316. };
  317. static_assert(sizeof(FontMetric) == 48, "size of lts::FontMetric should be 48");
  318. typedef float Vector4f[4];
  319. typedef Vector4f Matrix4f[4];
  320. static_assert(sizeof(Vector4f) == 16, "size of lts::Vector4f should be 16");
  321. static_assert(sizeof(Matrix4f) == 64, "size of lts::Matrix4f should be 64");
  322. /* contants ***********************************************************************************************************************/
  323. static const ImageModes ImageModeReplaceAll = {
  324. ImageMode::Replace,
  325. ImageMode::Replace,
  326. ImageMode::Replace,
  327. ImageMode::Replace
  328. };
  329. static const ImageModes ImageModeModulateAlpha = {
  330. ImageMode::Replace,
  331. ImageMode::Replace,
  332. ImageMode::Replace,
  333. ImageMode::Modulate
  334. };
  335. static const ImageModes ImageModeModulateAll = {
  336. ImageMode::Modulate,
  337. ImageMode::Modulate,
  338. ImageMode::Modulate,
  339. ImageMode::Modulate
  340. };
  341. ColorChannels ColorChannelsRGB({ ColorChannel::Red, ColorChannel::Green, ColorChannel::Blue });
  342. ColorChannels ColorChannelsRGBA({ ColorChannel::Red, ColorChannel::Green, ColorChannel::Blue, ColorChannel::Alpha });
  343. /* exeption ***********************************************************************************************************************/
  344. class Exception : public std::exception
  345. {
  346. private:
  347. std::string _message;
  348. ErrorCode _errorCode;
  349. public:
  350. ErrorCode getErrorCode() const;
  351. std::string getMessage() const;
  352. virtual const char* what() const throw();
  353. Exception(std::string message, ErrorCode errorCode = ErrorCode::Unknown);
  354. ~Exception() throw();
  355. };
  356. /* library ************************************************************************************************************************/
  357. class Library
  358. {
  359. public:
  360. struct Impl;
  361. #if defined(LTS_WINDOWS)
  362. typedef HMODULE Handle; //!< shader file handle
  363. #elif defined(LTS_LINUX)
  364. typedef void* Handle; //!< shader file handle
  365. #else
  366. #error "unknown operation system"
  367. #endif
  368. private:
  369. Impl* _impl;
  370. Handle _handle;
  371. Library(const Library& that) = delete;
  372. public:
  373. const Impl& getImpl() const;
  374. ErrorCode getLastErrorCode() const;
  375. std::string getLastErrorMsg() const;
  376. Library(const std::string& libName);
  377. ~Library();
  378. };
  379. /* context ************************************************************************************************************************/
  380. class Context
  381. {
  382. friend class Image;
  383. friend class PostProcessor;
  384. friend class FontCreator;
  385. friend class Renderer;
  386. private:
  387. const Library::Impl& _impl;
  388. ContextHandle _handle;
  389. Context(const Context&) = delete;
  390. public:
  391. ContextHandle getHandle() const;
  392. CodePage getCodePage() const;
  393. WideChar getDefaultChar() const;
  394. void setCodePage(const CodePage value);
  395. void setDefaultChar(const WideChar value);
  396. Context(const Library& library);
  397. };
  398. /* char ***************************************************************************************************************************/
  399. class Char
  400. {
  401. private:
  402. const Library::Impl& _impl;
  403. CharHandle _handle;
  404. Char(const Char&) = delete;
  405. public:
  406. CharHandle getHandle() const;
  407. WideChar getCharCode() const;
  408. GlyphMetric getGlyphMetric() const;
  409. void setGlyphMetric(const GlyphMetric& value);
  410. Char(const Library::Impl& impl, CharHandle handle);
  411. };
  412. /* image **************************************************************************************************************************/
  413. class Image
  414. {
  415. public:
  416. typedef void (*LoadCallback) (Image& image, int x, int y, Color4f& pixel, void* args);
  417. typedef Color4f (*BlendCallback)(Image& image, Color4f src, Color4f dst, void* args);
  418. typedef std::function<void(Image& image, int x, int y, Color4f& pixel)> LoadFunction;
  419. typedef std::function<Color4f(Image& image, Color4f src, Color4f dst)> BlendFunction;
  420. private:
  421. const Library::Impl& _impl;
  422. ImageHandle _handle;
  423. bool _ownsHandle;
  424. Image(const Image&) = delete;
  425. public:
  426. ImageHandle getHandle() const;
  427. bool getIsEmpty() const;
  428. int getWidth() const;
  429. int getHeight() const;
  430. int getLineSize() const;
  431. int getDataSize() const;
  432. Format getFormat() const;
  433. void* getData() const;
  434. void* getScanline(int index) const;
  435. bool getPixelAt(int x, int y, Color4f& color) const;
  436. void assign(const Image& image);
  437. void createEmpty(Format format, int width, int height);
  438. void loadFromFunc(LoadCallback callback, void* args);
  439. void loadFromFunc(LoadFunction func);
  440. void resize(int width, int height, int x, int y);
  441. void fillColor(const Color4f& color, const ColorChannels& mask, const ImageModes& modes);
  442. void fillPattern(const Image& pattern, int x, int y, const ColorChannels& mask, const ImageModes& modes);
  443. void blend(const Image& image, int x, int y, BlendCallback callback, void* args);
  444. void blend(const Image& image, int x, int y, BlendFunction func);
  445. void blur(float horzRad, float horzStr, float vertRad, float vertStr, const ColorChannels& mask);
  446. Image(const Library::Impl& impl, ImageHandle handle);
  447. Image(const Context& context);
  448. virtual ~Image();
  449. private:
  450. static void WINAPI loadCallback(ImageHandle handle, int x, int y, lts::Color4f& pixel, void* args);
  451. static void WINAPI loadFunc(ImageHandle handle, int x, int y, lts::Color4f& pixel, void* args);
  452. struct LoadArgs
  453. {
  454. void* args;
  455. Image* image;
  456. LoadCallback callback;
  457. LoadFunction* func;
  458. };
  459. static void WINAPI blendCallback(ImageHandle handle, lts::Color4f src, lts::Color4f dst, lts::Color4f& result, void* args);
  460. static void WINAPI blendFunc(ImageHandle handle, lts::Color4f src, lts::Color4f dst, lts::Color4f& result, void* args);
  461. struct BlendArgs
  462. {
  463. void* args;
  464. Image* image;
  465. BlendCallback callback;
  466. BlendFunction* func;
  467. };
  468. };
  469. /* post processor *****************************************************************************************************************/
  470. class PostProcessor
  471. {
  472. private:
  473. PostProcessorHandle _handle;
  474. PostProcessor(const PostProcessor&) = delete;
  475. protected:
  476. const Library::Impl& _impl;
  477. void setHandle(PostProcessorHandle handle);
  478. PostProcessor(const Context& context);
  479. public:
  480. void execute(Char& c, Image& i);
  481. PostProcessorHandle getHandle() const;
  482. void addRange(CharRangeUsage usage, WideChar start, WideChar stop);
  483. void addChars(CharRangeUsage usage, const WideChar* chars);
  484. void clearRanges();
  485. virtual ~PostProcessor();
  486. };
  487. /* post processor fill color ******************************************************************************************************/
  488. class PostProcessorFillColor final : public PostProcessor
  489. {
  490. private:
  491. Color4f _color;
  492. ImageModes _modes;
  493. ColorChannels _channels;
  494. public:
  495. const Color4f& getColor() const;
  496. const ImageModes& getModes() const;
  497. const ColorChannels& getChannels() const;
  498. PostProcessorFillColor(
  499. const Context& context,
  500. const Color4f& color,
  501. const ImageModes& modes,
  502. const ColorChannels& channels);
  503. };
  504. /* post processor fill pattern ****************************************************************************************************/
  505. class PostProcessorFillPattern final : public PostProcessor
  506. {
  507. private:
  508. const Image& _pattern;
  509. Position _position;
  510. ImageModes _modes;
  511. ColorChannels _channels;
  512. public:
  513. const Image& getPattern() const;
  514. const Position& getPosition() const;
  515. const ImageModes& getModes() const;
  516. const ColorChannels& getChannels() const;
  517. PostProcessorFillPattern(
  518. const Context& context,
  519. const Image& pattern,
  520. const Position& pos,
  521. const ImageModes& modes,
  522. const ColorChannels& channels);
  523. };
  524. /* post processor border **********************************************************************************************************/
  525. class PostProcessorBorder final : public PostProcessor
  526. {
  527. private:
  528. float _width;
  529. float _strength;
  530. Color4f _color;
  531. bool _keepSize;
  532. public:
  533. float getWidth() const;
  534. float getStrength() const;
  535. Color4f getColor() const;
  536. bool getKeepSize() const;
  537. PostProcessorBorder(
  538. const Context& context,
  539. float width,
  540. float strength,
  541. const Color4f& color,
  542. bool keepSize);
  543. };
  544. /* post processor shadow **********************************************************************************************************/
  545. class PostProcessorShadow final : public PostProcessor
  546. {
  547. private:
  548. float _radius;
  549. float _strength;
  550. Position _offset;
  551. Color4f _color;
  552. public:
  553. float getRadius() const;
  554. float getStrength() const;
  555. Position getOffset() const;
  556. Color4f getColor() const;
  557. PostProcessorShadow(
  558. const Context& context,
  559. float radius,
  560. float strength,
  561. const Position& offset,
  562. const Color4f& color);
  563. };
  564. /* post processor custom **********************************************************************************************************/
  565. class PostProcessorCustom : public PostProcessor
  566. {
  567. protected:
  568. virtual void doExecute(Char& c, Image& i);
  569. public:
  570. PostProcessorCustom(const Context& context);
  571. public:
  572. static void WINAPI executeCallback(CharHandle charHandle, ImageHandle imageHandle, void* args);
  573. };
  574. /* post processor list ************************************************************************************************************/
  575. template<typename T>
  576. class PostProcessorList : public PostProcessorCustom,
  577. public std::list<T>
  578. {
  579. protected:
  580. void doExecute(Char& c, Image& i) override;
  581. public:
  582. PostProcessorList(const Context& context);
  583. };
  584. /* font ***************************************************************************************************************************/
  585. class Font
  586. {
  587. public:
  588. struct Names
  589. {
  590. std::string fontname;
  591. std::string copyright;
  592. std::string facename;
  593. std::string stylename;
  594. std::string fullname;
  595. };
  596. private:
  597. const Library::Impl& _impl;
  598. FontHandle _handle;
  599. FontMetric _metric;
  600. Names _names;
  601. PostProcessor* _postProcessor;
  602. Font(const Font&) = delete;
  603. public:
  604. FontHandle getHandle() const;
  605. const Names& getNames() const;
  606. const FontMetric& getMetric() const;
  607. PostProcessor* getPostProcessor() const;
  608. int getTabWidth() const;
  609. int getCharSpacing() const;
  610. int getLineSpacing() const;
  611. void setPostProcessor(PostProcessor* value);
  612. void setTabWidth(int value);
  613. void setCharSpacing(int value);
  614. void setLineSpacing(int value);
  615. Font(const Library::Impl& impl, FontHandle handle);
  616. virtual ~Font();
  617. };
  618. typedef std::unique_ptr<Font> FontPtrU;
  619. /* font creator *******************************************************************************************************************/
  620. class FontCreator
  621. {
  622. private:
  623. FontCreatorHandle _handle;
  624. FontCreator(const FontCreator&);
  625. protected:
  626. const Library::Impl& _impl;
  627. void setHandle(FontCreatorHandle value);
  628. FontCreator(const Context& context);
  629. public:
  630. FontCreatorHandle getHandle() const;
  631. FontPtrU getFontByName (const std::string& fontname, int size, FontStyles styles, AntiAliasing antiAliasing);
  632. FontPtrU getFontByFile (const std::string& filename, int size, FontStyles styles, AntiAliasing antiAliasing);
  633. FontPtrU getFontByStream( std::istream& stream, int size, FontStyles styles, AntiAliasing antiAliasing);
  634. virtual ~FontCreator();
  635. public:
  636. static int WINAPI StreamReadCallback(void* args, void* buffer, int count);
  637. static int WINAPI StreamSeekCallback(void* args, StreamOrigin origin, int offset);
  638. };
  639. /* font creator GDI ***************************************************************************************************************/
  640. class FontCreatorGDI : public FontCreator
  641. {
  642. public:
  643. FontCreatorGDI(const Context& context);
  644. };
  645. /* font creator free type *********************************************************************************************************/
  646. class FontCreatorFreeType : public FontCreator
  647. {
  648. public:
  649. FontCreatorFreeType(const Context& context);
  650. };
  651. /* text block *********************************************************************************************************************/
  652. class TextBlock
  653. {
  654. private:
  655. const Library::Impl& _impl;
  656. TextBlockHandle _handle;
  657. Font* _font;
  658. TextBlock(const TextBlock&);
  659. public:
  660. TextBlockHandle getHandle() const;
  661. Rect getRect() const;
  662. int getWidth() const;
  663. int getHeight() const;
  664. BlockFlags getFlags() const;
  665. int getTop() const;
  666. int getLeft() const;
  667. VertAlign getVertAlign() const;
  668. HorzAlign getHorzAlign() const;
  669. Clipping getClipping() const;
  670. Color4f getColor() const;
  671. Font* getFont() const;
  672. void setTop(int value);
  673. void setLeft(int value);
  674. void setVertAlign(VertAlign value);
  675. void setHorzAlign(HorzAlign value);
  676. void setClipping(Clipping value);
  677. void setColor(const Color4f& value);
  678. void setFont(Font* font);
  679. int getActualBlockHeight() const;
  680. void textOutA(const char* text);
  681. void textOutA(const std::string& text);
  682. void textOutW(const WideChar* text);
  683. void textOutW(const std::wstring& text);
  684. int getTextWidthA(const char* text);
  685. int getTextWidthA(const std::string& text);
  686. int getTextWidthW(const WideChar* text);
  687. int getTextWidthW(const std::wstring& text);
  688. TextBlock(const Library::Impl& impl, TextBlockHandle handle);
  689. virtual ~TextBlock();
  690. };
  691. typedef std::unique_ptr<TextBlock> TextBlockPtrU;
  692. /* renderer ***********************************************************************************************************************/
  693. class Renderer
  694. {
  695. private:
  696. RendererHandle _handle;
  697. Renderer(const Renderer&) = delete;
  698. protected:
  699. const Library::Impl& _impl;
  700. void setHandle(RendererHandle value);
  701. Renderer(const Context& context);
  702. public:
  703. RendererHandle getHandle() const;
  704. TextBlockPtrU beginBlock(int top, int left, int width, int height, BlockFlags flags);
  705. void endBlock(TextBlockPtrU block);
  706. void abortBlock(TextBlockPtrU block);
  707. int getTextWidthA(const Font& font, const char* text);
  708. int getTextWidthA(const Font& font, const std::string& text);
  709. int getTextWidthW(const Font& font, const WideChar* text);
  710. int getTextWidthW(const Font& font, const std::wstring& text);
  711. virtual ~Renderer();
  712. };
  713. /* renderer OpenGL ****************************************************************************************************************/
  714. class RendererOpenGL : public Renderer
  715. {
  716. public:
  717. RendererOpenGL(const Context& context, Format format);
  718. };
  719. /* renderer OpenGLES **************************************************************************************************************/
  720. class RendererOpenGLES : public Renderer
  721. {
  722. public:
  723. RendererOpenGLES(const Context& context, Format format);
  724. };
  725. /* renderer custom ****************************************************************************************************************/
  726. class RendererCustom : public Renderer
  727. {
  728. protected:
  729. Position _drawPos;
  730. Color4f _color;
  731. virtual void beginRender();
  732. virtual void endRender();
  733. virtual Position getDrawPos();
  734. virtual void setDrawPos(const Position& value);
  735. virtual void moveDrawPos(const Position& offset);
  736. virtual void setColor(const Color4f& color);
  737. virtual void render(RenderRef ref, int forcedWidth = 0);
  738. virtual RenderRef createRenderRef(Char& c, const Image& img);
  739. virtual void freeRenderRef(RenderRef ref);
  740. public:
  741. RendererCustom(const Context& context, Format format);
  742. public:
  743. static void WINAPI BeginRenderCallback (void* args);
  744. static void WINAPI EndRendererCallback (void* args);
  745. static lts::Position WINAPI GetDrawPosCallback (void* args);
  746. static void WINAPI SetDrawPosCallback (lts::Position value, void* args);
  747. static void WINAPI MoveDrawPosCallback (lts::Position value, void* args);
  748. static void WINAPI SetColorCallback (lts::Color4f value, void* args);
  749. static void WINAPI RenderCallback (void* ref, int forcedWidth, void* args);
  750. static void* WINAPI CreateRefCallback (lts::CharHandle charHandle, lts::ImageHandle imageHandle, void* args);
  751. static void WINAPI FreeRefCallback (void* ref, void* args);
  752. };
  753. }
  754. /**********************************************************************************************************************************/
  755. /* private implementation */
  756. /**********************************************************************************************************************************/
  757. #if defined(LTS_WINDOWS)
  758. lts::Library::Handle libOpen(const char* name)
  759. { return LoadLibrary(name); };
  760. template <typename T>
  761. T getAddr(lts::Library::Handle handle, const char* name)
  762. { return reinterpret_cast<T>(GetProcAddress(handle, name)); };
  763. int libClose(lts::Library::Handle handle)
  764. { return FreeLibrary(handle); };
  765. #elif defined(LTS_LINUX)
  766. lts::Library::Handle libOpen(const char* name)
  767. { return dlopen(name, RTLD_LAZY); };
  768. template <typename T>
  769. T getAddr(lts::Library::Handle handle, const char* name)
  770. { return reinterpret_cast<T>(dlsym(handle, name)); };
  771. int libClose(lts::Library::Handle handle)
  772. { return !dlclose(handle); };
  773. #else
  774. # error "unknown operation system"
  775. #endif
  776. /* Library::Impl ******************************************************************************************************************/
  777. struct lts::Library::Impl
  778. {
  779. public: /* stream */
  780. struct StreamData
  781. {
  782. typedef int (WINAPI *stream_read_t)(void* args, void* buffer, int count);
  783. typedef int (WINAPI *stream_seek_t)(void* args, StreamOrigin origin, int offset);
  784. void* args;
  785. stream_read_t read;
  786. stream_seek_t seek;
  787. };
  788. public: /* custom post processor */
  789. struct PostProcessorData
  790. {
  791. typedef void (WINAPI *post_processor_execute_t)(lts::CharHandle charHandle, lts::ImageHandle imageHandle, void* args);
  792. void* args;
  793. post_processor_execute_t execute;
  794. };
  795. public: /* custom renderer */
  796. struct RendererCustomData
  797. {
  798. typedef void (WINAPI *renderer_begin_render_t) (void* args);
  799. typedef void (WINAPI *renderer_end_render_t) (void* args);
  800. typedef lts::Position (WINAPI *renderer_get_draw_pos_t) (void* args);
  801. typedef void (WINAPI *renderer_set_draw_pos_t) (lts::Position value, void* args);
  802. typedef void (WINAPI *renderer_move_draw_pos_t) (lts::Position value, void* args);
  803. typedef void (WINAPI *renderer_set_color_t) (lts::Color4f value, void* args);
  804. typedef void (WINAPI *renderer_render) (void* ref, int forcedWidth, void* args);
  805. typedef void* (WINAPI *renderer_create_ref) (lts::CharHandle charHandle, lts::ImageHandle imageHandle, void* args);
  806. typedef void (WINAPI *renderer_free_ref) (void* ref, void* args);
  807. void* args;
  808. renderer_begin_render_t beginRender;
  809. renderer_end_render_t endRender;
  810. renderer_get_draw_pos_t getDrawPos;
  811. renderer_set_draw_pos_t setDrawPos;
  812. renderer_move_draw_pos_t moveDrawPos;
  813. renderer_set_color_t setColor;
  814. renderer_render render;
  815. renderer_create_ref createRef;
  816. renderer_free_ref freeRef;
  817. };
  818. public: /* callbacks */
  819. typedef void (WINAPI *image_load_callback_t) (lts::ImageHandle handle, int x, int y, lts::Color4f& pixel, void* args);
  820. typedef void (WINAPI *image_blend_callback_t)(lts::ImageHandle handle, lts::Color4f src, lts::Color4f dst, lts::Color4f& result, void* args);
  821. typedef lts::ContextHandle (WINAPI *context_create_t) ();
  822. typedef lts::ErrorCode (WINAPI *context_get_code_page_t) (lts::ContextHandle handle, lts::CodePage& value);
  823. typedef lts::ErrorCode (WINAPI *context_get_default_char_t) (lts::ContextHandle handle, WideChar& value);
  824. typedef lts::ErrorCode (WINAPI *context_set_code_page_t) (lts::ContextHandle handle, lts::CodePage value);
  825. typedef lts::ErrorCode (WINAPI *context_set_default_char_t) (lts::ContextHandle handle, WideChar value);
  826. typedef WideChar* (WINAPI *context_ansi_to_wide_t) (lts::ContextHandle handle, const char* text);
  827. typedef lts::ErrorCode (WINAPI *context_destroy_t) (lts::ContextHandle handle);
  828. typedef lts::RendererHandle (WINAPI *renderer_create_t) (lts::ContextHandle handle, lts::RendererType type, lts::Format format);
  829. typedef lts::RendererHandle (WINAPI *renderer_create_custom_t) (lts::ContextHandle handle, lts::Format format, const RendererCustomData& data);
  830. typedef lts::TextBlockHandle (WINAPI *renderer_begin_block_t) (lts::RendererHandle handle, int top, int left, int width, int height, uint32_t flags);
  831. typedef lts::ErrorCode (WINAPI *renderer_end_block_t) (lts::RendererHandle handle, lts::TextBlockHandle block);
  832. typedef lts::ErrorCode (WINAPI *renderer_abort_block_t) (lts::RendererHandle handle, lts::TextBlockHandle block);
  833. typedef int (WINAPI *renderer_get_text_width_a_t) (lts::RendererHandle handle, lts::FontHandle font, const char* text);
  834. typedef int (WINAPI *renderer_get_text_width_w_t) (lts::RendererHandle handle, lts::FontHandle font, const WideChar* text);
  835. typedef lts::ErrorCode (WINAPI *renderer_destroy_t) (lts::RendererHandle handle);
  836. typedef lts::FontCreatorHandle (WINAPI *font_creator_create_t) (lts::ContextHandle handle, lts::FontCreatorType type);
  837. typedef lts::FontHandle (WINAPI *font_creator_get_font_by_name_t) (lts::FontCreatorHandle handle, const char* fontname, int size, uint32_t style, lts::AntiAliasing antialiasing);
  838. typedef lts::FontHandle (WINAPI *font_creator_get_font_by_file_t) (lts::FontCreatorHandle handle, const char* filename, int size, uint32_t style, lts::AntiAliasing antialiasing);
  839. typedef lts::FontHandle (WINAPI *font_creator_get_font_by_stream_t) (lts::FontCreatorHandle handle, const StreamData& stream, int size, uint32_t style, lts::AntiAliasing antialiasing);
  840. typedef lts::ErrorCode (WINAPI *font_creator_destroy_t) (lts::FontCreatorHandle handle);
  841. typedef lts::PostProcessorHandle(WINAPI *font_get_post_processor_t) (lts::FontHandle handle);
  842. typedef lts::ErrorCode (WINAPI *font_get_tab_width_t) (lts::FontHandle handle, int& value);
  843. typedef lts::ErrorCode (WINAPI *font_get_char_spacing_t) (lts::FontHandle handle, int& value);
  844. typedef lts::ErrorCode (WINAPI *font_get_line_spacing_t) (lts::FontHandle handle, float& value);
  845. typedef lts::ErrorCode (WINAPI *font_get_metric_t) (lts::FontHandle handle, lts::FontMetric& value);
  846. typedef const char* (WINAPI *font_get_fontname_t) (lts::FontHandle handle);
  847. typedef const char* (WINAPI *font_get_facename_t) (lts::FontHandle handle);
  848. typedef const char* (WINAPI *font_get_stylename_t) (lts::FontHandle handle);
  849. typedef const char* (WINAPI *font_get_fullname_t) (lts::FontHandle handle);
  850. typedef const char* (WINAPI *font_get_copyright_t) (lts::FontHandle handle);
  851. typedef lts::ErrorCode (WINAPI *font_set_post_processor_t) (lts::FontHandle handle, lts::PostProcessorHandle pp);
  852. typedef lts::ErrorCode (WINAPI *font_set_tab_width_t) (lts::FontHandle handle, int value);
  853. typedef lts::ErrorCode (WINAPI *font_set_char_spacing_t) (lts::FontHandle handle, int value);
  854. typedef lts::ErrorCode (WINAPI *font_set_line_spacing_t) (lts::FontHandle handle, float value);
  855. typedef lts::ErrorCode (WINAPI *font_destroy_t) (lts::FontHandle handle);
  856. typedef lts::ErrorCode (WINAPI *text_block_get_rect_t) (lts::TextBlockHandle handle, lts::Rect& value);
  857. typedef lts::ErrorCode (WINAPI *text_block_get_width_t) (lts::TextBlockHandle handle, int& value);
  858. typedef lts::ErrorCode (WINAPI *text_block_get_height_t) (lts::TextBlockHandle handle, int& value);
  859. typedef lts::ErrorCode (WINAPI *text_block_get_flags_t) (lts::TextBlockHandle handle, uint32_t& value);
  860. typedef lts::ErrorCode (WINAPI *text_block_get_top_t) (lts::TextBlockHandle handle, int& value);
  861. typedef lts::ErrorCode (WINAPI *text_block_get_left_t) (lts::TextBlockHandle handle, int& value);
  862. typedef lts::ErrorCode (WINAPI *text_block_get_vert_align_t) (lts::TextBlockHandle handle, lts::VertAlign& value);
  863. typedef lts::ErrorCode (WINAPI *text_block_get_horz_align_t) (lts::TextBlockHandle handle, lts::HorzAlign& value);
  864. typedef lts::ErrorCode (WINAPI *text_block_get_clipping_t) (lts::TextBlockHandle handle, lts::Clipping& value);
  865. typedef lts::ErrorCode (WINAPI *text_block_get_color_t) (lts::TextBlockHandle handle, lts::Color4f& value);
  866. typedef lts::ErrorCode (WINAPI *text_block_get_font_t) (lts::TextBlockHandle handle, lts::FontHandle& value);
  867. typedef lts::ErrorCode (WINAPI *text_block_set_top_t) (lts::TextBlockHandle handle, int value);
  868. typedef lts::ErrorCode (WINAPI *text_block_set_left_t) (lts::TextBlockHandle handle, int value);
  869. typedef lts::ErrorCode (WINAPI *text_block_set_vert_align_t) (lts::TextBlockHandle handle, lts::VertAlign value);
  870. typedef lts::ErrorCode (WINAPI *text_block_set_horz_align_t) (lts::TextBlockHandle handle, lts::HorzAlign value);
  871. typedef lts::ErrorCode (WINAPI *text_block_set_clipping_t) (lts::TextBlockHandle handle, lts::Clipping value);
  872. typedef lts::ErrorCode (WINAPI *text_block_set_color_t) (lts::TextBlockHandle handle, lts::Color4f value);
  873. typedef lts::ErrorCode (WINAPI *text_block_set_font_t) (lts::TextBlockHandle handle, lts::FontHandle value);
  874. typedef int (WINAPI *text_block_get_actual_height_t) (lts::TextBlockHandle handle);
  875. typedef int (WINAPI *text_block_get_text_width_a_t) (lts::TextBlockHandle handle, const char* text);
  876. typedef int (WINAPI *text_block_get_text_width_w_t) (lts::TextBlockHandle handle, const WideChar* text);
  877. typedef lts::ErrorCode (WINAPI *text_block_text_out_a_t) (lts::TextBlockHandle handle, const char* text);
  878. typedef lts::ErrorCode (WINAPI *text_block_text_out_w_t) (lts::TextBlockHandle handle, const WideChar* text);
  879. typedef lts::ErrorCode (WINAPI *text_block_destroy_t) (lts::TextBlockHandle handle);
  880. typedef lts::ImageHandle (WINAPI *image_create_t) (lts::ContextHandle handle);
  881. typedef lts::ErrorCode (WINAPI *image_is_empty_t) (lts::ImageHandle handle, bool& value);
  882. typedef int (WINAPI *image_get_width_t) (lts::ImageHandle handle);
  883. typedef int (WINAPI *image_get_height_t) (lts::ImageHandle handle);
  884. typedef int (WINAPI *image_get_line_size_t) (lts::ImageHandle handle);
  885. typedef int (WINAPI *image_get_data_size_t) (lts::ImageHandle handle);
  886. typedef lts::ErrorCode (WINAPI *image_get_format_t) (lts::ImageHandle handle, lts::Format& value);
  887. typedef void* (WINAPI *image_get_data_t) (lts::ImageHandle handle);
  888. typedef void* (WINAPI *image_get_scanline_t) (lts::ImageHandle handle, int index);
  889. typedef lts::ErrorCode (WINAPI *image_get_pixel_at_t) (lts::ImageHandle handle, int x, int y, lts::Color4f pixel);
  890. typedef lts::ErrorCode (WINAPI *image_assign_t) (lts::ImageHandle handle, lts::ImageHandle source);
  891. typedef lts::ErrorCode (WINAPI *image_create_empty_t) (lts::ImageHandle handle, lts::Format format, int width, int height);
  892. typedef lts::ErrorCode (WINAPI *image_load_from_func_t) (lts::ImageHandle handle, image_load_callback_t callback, void* args);
  893. typedef lts::ErrorCode (WINAPI *image_resize_t) (lts::ImageHandle handle, int width, int height, int x, int y);
  894. typedef lts::ErrorCode (WINAPI *image_fill_color_t) (lts::ImageHandle handle, lts::Color4f color, uint32_t mask, lts::ImageMode modes[4]);
  895. typedef lts::ErrorCode (WINAPI *image_fill_pattern_t) (lts::ImageHandle handle, lts::ImageHandle pattern, int x, int y, uint32_t mask, lts::ImageMode modes[4]);
  896. typedef lts::ErrorCode (WINAPI *image_blend_t) (lts::ImageHandle handle, lts::ImageHandle source, int x, int y, image_blend_callback_t callback, void* args);
  897. typedef lts::ErrorCode (WINAPI *image_blur_t) (lts::ImageHandle handle, float horzRad, float horzStr, float vertRad, float vertStr, uint32_t mask);
  898. typedef lts::ErrorCode (WINAPI *image_destroy_t) (lts::ImageHandle handle);
  899. typedef lts::ErrorCode (WINAPI *post_processor_add_range_t) (lts::PostProcessorHandle handle, lts::CharRangeUsage usage, WideChar start, wchar_t stop);
  900. typedef lts::ErrorCode (WINAPI *post_processor_add_chars_t) (lts::PostProcessorHandle handle, lts::CharRangeUsage usage, const WideChar* chars);
  901. typedef lts::ErrorCode (WINAPI *post_processor_clear_ranges_t) (lts::PostProcessorHandle handle);
  902. typedef lts::ErrorCode (WINAPI *post_processor_execute_t) (lts::PostProcessorHandle handle, lts::CharHandle charHandle, lts::ImageHandle image);
  903. typedef lts::PostProcessorHandle(WINAPI *post_processor_fill_color_create_t) (lts::PostProcessorHandle handle, lts::Color4f color, lts::ImageMode modes[4], uint32_t channels);
  904. typedef lts::PostProcessorHandle(WINAPI *post_processor_fill_pattern_create_t) (lts::PostProcessorHandle handle, lts::ImageHandle pattern, bool ownsPattern, lts::Position position, lts::ImageMode modes[4], uint32_t channels);
  905. typedef lts::PostProcessorHandle(WINAPI *post_processor_border_create_t) (lts::PostProcessorHandle handle, float width, float strength, lts::Color4f color, bool keepSize);
  906. typedef lts::PostProcessorHandle(WINAPI *post_processor_shadow_create_t) (lts::PostProcessorHandle handle, float radius, float strength, lts::Position offset, lts::Color4f color);
  907. typedef lts::PostProcessorHandle(WINAPI *post_processor_custom_create_t) (lts::PostProcessorHandle handle, PostProcessorData& data);
  908. typedef lts::ErrorCode (WINAPI *post_processor_destroy_t) (lts::PostProcessorHandle handle);
  909. typedef lts::ErrorCode (WINAPI *char_get_char_code_t) (lts::CharHandle handle, WideChar& value);
  910. typedef lts::ErrorCode (WINAPI *char_get_glyph_metric_t) (lts::CharHandle handle, lts::GlyphMetric& value);
  911. typedef lts::ErrorCode (WINAPI *char_set_glyph_metric_t) (lts::CharHandle handle, const lts::GlyphMetric& value);
  912. typedef lts::ErrorCode (WINAPI *initialize_t) ();
  913. typedef lts::ErrorCode (WINAPI *get_last_error_code_t) ();
  914. typedef const char* (WINAPI *get_last_error_msg_t) ();
  915. typedef lts::ErrorCode (WINAPI *finalize_t) ();
  916. private:
  917. lts::Library::Handle _handle;
  918. template <typename T>
  919. inline void loadProc(T& proc, const char* name)
  920. {
  921. proc = getAddr<T>(_handle, name);
  922. if (!proc)
  923. throw lts::Exception(std::string("unable to load method from library: ") + name, lts::ErrorCode::InvalidMethodName);
  924. }
  925. public:
  926. context_create_t context_create;
  927. context_get_code_page_t context_get_code_page;
  928. context_get_default_char_t context_get_default_char;
  929. context_set_code_page_t context_set_code_page;
  930. context_set_default_char_t context_set_default_char;
  931. context_ansi_to_wide_t context_ansi_to_wide;
  932. context_destroy_t context_destroy;
  933. renderer_create_t renderer_create;
  934. renderer_create_custom_t renderer_create_custom;
  935. renderer_begin_block_t renderer_begin_block;
  936. renderer_end_block_t renderer_end_block;
  937. renderer_abort_block_t renderer_abort_block;
  938. renderer_get_text_width_a_t renderer_get_text_width_a;
  939. renderer_get_text_width_w_t renderer_get_text_width_w;
  940. renderer_destroy_t renderer_destroy;
  941. font_creator_create_t font_creator_create;
  942. font_creator_get_font_by_name_t font_creator_get_font_by_name;
  943. font_creator_get_font_by_file_t font_creator_get_font_by_file;
  944. font_creator_get_font_by_stream_t font_creator_get_font_by_stream;
  945. font_creator_destroy_t font_creator_destroy;
  946. font_get_post_processor_t font_get_post_processor;
  947. font_get_tab_width_t font_get_tab_width;
  948. font_get_char_spacing_t font_get_char_spacing;
  949. font_get_line_spacing_t font_get_line_spacing;
  950. font_get_metric_t font_get_metric;
  951. font_get_fontname_t font_get_fontname;
  952. font_get_facename_t font_get_facename;
  953. font_get_stylename_t font_get_stylename;
  954. font_get_fullname_t font_get_fullname;
  955. font_get_copyright_t font_get_copyright;
  956. font_set_post_processor_t font_set_post_processor;
  957. font_set_tab_width_t font_set_tab_width;
  958. font_set_char_spacing_t font_set_char_spacing;
  959. font_set_line_spacing_t font_set_line_spacing;
  960. font_destroy_t font_destroy;
  961. text_block_get_rect_t text_block_get_rect;
  962. text_block_get_width_t text_block_get_width;
  963. text_block_get_height_t text_block_get_height;
  964. text_block_get_flags_t text_block_get_flags;
  965. text_block_get_top_t text_block_get_top;
  966. text_block_get_left_t text_block_get_left;
  967. text_block_get_vert_align_t text_block_get_vert_align;
  968. text_block_get_horz_align_t text_block_get_horz_align;
  969. text_block_get_clipping_t text_block_get_clipping;
  970. text_block_get_color_t text_block_get_color;
  971. text_block_get_font_t text_block_get_font;
  972. text_block_set_top_t text_block_set_top;
  973. text_block_set_left_t text_block_set_left;
  974. text_block_set_vert_align_t text_block_set_vert_align;
  975. text_block_set_horz_align_t text_block_set_horz_align;
  976. text_block_set_clipping_t text_block_set_clipping;
  977. text_block_set_color_t text_block_set_color;
  978. text_block_set_font_t text_block_set_font;
  979. text_block_get_actual_height_t text_block_get_actual_height;
  980. text_block_get_text_width_a_t text_block_get_text_width_a;
  981. text_block_get_text_width_w_t text_block_get_text_width_w;
  982. text_block_text_out_a_t text_block_text_out_a;
  983. text_block_text_out_w_t text_block_text_out_w;
  984. text_block_destroy_t text_block_destroy;
  985. image_create_t image_create;
  986. image_is_empty_t image_is_empty;
  987. image_get_width_t image_get_width;
  988. image_get_height_t image_get_height;
  989. image_get_line_size_t image_get_line_size;
  990. image_get_data_size_t image_get_data_size;
  991. image_get_format_t image_get_format;
  992. image_get_data_t image_get_data;
  993. image_get_scanline_t image_get_scanline;
  994. image_get_pixel_at_t image_get_pixel_at;
  995. image_assign_t image_assign;
  996. image_create_empty_t image_create_empty;
  997. image_load_from_func_t image_load_from_func;
  998. image_resize_t image_resize;
  999. image_fill_color_t image_fill_color;
  1000. image_fill_pattern_t image_fill_pattern;
  1001. image_blend_t image_blend;
  1002. image_blur_t image_blur;
  1003. image_destroy_t image_destroy;
  1004. post_processor_add_range_t post_processor_add_range;
  1005. post_processor_add_chars_t post_processor_add_chars;
  1006. post_processor_clear_ranges_t post_processor_clear_ranges;
  1007. post_processor_execute_t post_processor_execute;
  1008. post_processor_fill_color_create_t post_processor_fill_color_create;
  1009. post_processor_fill_pattern_create_t post_processor_fill_pattern_create;
  1010. post_processor_border_create_t post_processor_border_create;
  1011. post_processor_shadow_create_t post_processor_shadow_create;
  1012. post_processor_custom_create_t post_processor_custom_create;
  1013. post_processor_destroy_t post_processor_destroy;
  1014. char_get_char_code_t char_get_char_code;
  1015. char_get_glyph_metric_t char_get_glyph_metric;
  1016. char_set_glyph_metric_t char_set_glyph_metric;
  1017. initialize_t initialize;
  1018. get_last_error_code_t get_last_error_code;
  1019. get_last_error_msg_t get_last_error_msg;
  1020. finalize_t finalize;
  1021. public:
  1022. Impl(lts::Library::Handle handle) :
  1023. _handle (handle),
  1024. context_create (NULL),
  1025. context_get_code_page (NULL),
  1026. context_get_default_char (NULL),
  1027. context_set_code_page (NULL),
  1028. context_set_default_char (NULL),
  1029. context_ansi_to_wide (NULL),
  1030. context_destroy (NULL),
  1031. renderer_create (NULL),
  1032. renderer_create_custom (NULL),
  1033. renderer_begin_block (NULL),
  1034. renderer_end_block (NULL),
  1035. renderer_abort_block (NULL),
  1036. renderer_get_text_width_a (NULL),
  1037. renderer_get_text_width_w (NULL),
  1038. renderer_destroy (NULL),
  1039. font_creator_create (NULL),
  1040. font_creator_get_font_by_name (NULL),
  1041. font_creator_get_font_by_file (NULL),
  1042. font_creator_get_font_by_stream (NULL),
  1043. font_creator_destroy (NULL),
  1044. font_get_post_processor (NULL),
  1045. font_get_tab_width (NULL),
  1046. font_get_char_spacing (NULL),
  1047. font_get_line_spacing (NULL),
  1048. font_get_metric (NULL),
  1049. font_get_fontname (NULL),
  1050. font_get_facename (NULL),
  1051. font_get_stylename (NULL),
  1052. font_get_fullname (NULL),
  1053. font_get_copyright (NULL),
  1054. font_set_post_processor (NULL),
  1055. font_set_tab_width (NULL),
  1056. font_set_char_spacing (NULL),
  1057. font_set_line_spacing (NULL),
  1058. font_destroy (NULL),
  1059. text_block_get_rect (NULL),
  1060. text_block_get_width (NULL),
  1061. text_block_get_height (NULL),
  1062. text_block_get_flags (NULL),
  1063. text_block_get_top (NULL),
  1064. text_block_get_left (NULL),
  1065. text_block_get_vert_align (NULL),
  1066. text_block_get_horz_align (NULL),
  1067. text_block_get_clipping (NULL),
  1068. text_block_get_color (NULL),
  1069. text_block_get_font (NULL),
  1070. text_block_set_top (NULL),
  1071. text_block_set_left (NULL),
  1072. text_block_set_vert_align (NULL),
  1073. text_block_set_horz_align (NULL),
  1074. text_block_set_clipping (NULL),
  1075. text_block_set_color (NULL),
  1076. text_block_set_font (NULL),
  1077. text_block_get_actual_height (NULL),
  1078. text_block_get_text_width_a (NULL),
  1079. text_block_get_text_width_w (NULL),
  1080. text_block_text_out_a (NULL),
  1081. text_block_text_out_w (NULL),
  1082. text_block_destroy (NULL),
  1083. image_create (NULL),
  1084. image_is_empty (NULL),
  1085. image_get_width (NULL),
  1086. image_get_height (NULL),
  1087. image_get_line_size (NULL),
  1088. image_get_data_size (NULL),
  1089. image_get_format (NULL),
  1090. image_get_data (NULL),
  1091. image_get_scanline (NULL),
  1092. image_get_pixel_at (NULL),
  1093. image_assign (NULL),
  1094. image_create_empty (NULL),
  1095. image_load_from_func (NULL),
  1096. image_resize (NULL),
  1097. image_fill_color (NULL),
  1098. image_fill_pattern (NULL),
  1099. image_blend (NULL),
  1100. image_blur (NULL),
  1101. image_destroy (NULL),
  1102. post_processor_add_range (NULL),
  1103. post_processor_add_chars (NULL),
  1104. post_processor_clear_ranges (NULL),
  1105. post_processor_execute (NULL),
  1106. post_processor_fill_color_create (NULL),
  1107. post_processor_fill_pattern_create (NULL),
  1108. post_processor_border_create (NULL),
  1109. post_processor_shadow_create (NULL),
  1110. post_processor_custom_create (NULL),
  1111. post_processor_destroy (NULL),
  1112. char_get_char_code (NULL),
  1113. char_get_glyph_metric (NULL),
  1114. char_set_glyph_metric (NULL),
  1115. get_last_error_code (NULL),
  1116. get_last_error_msg (NULL)
  1117. {
  1118. loadProc(context_create, "ltsContextCreate");
  1119. loadProc(context_get_code_page, "ltsContextGetCodePage");
  1120. loadProc(context_get_default_char, "ltsContextGetDefaultChar");
  1121. loadProc(context_set_code_page, "ltsContextSetCodePage");
  1122. loadProc(context_set_default_char, "ltsContextSetDefaultChar");
  1123. loadProc(context_ansi_to_wide, "ltsContextAnsiToWide");
  1124. loadProc(context_destroy, "ltsContextDestroy");
  1125. loadProc(renderer_create, "ltsRendererCreate");
  1126. loadProc(renderer_create_custom, "ltsRendererCustomCreate");
  1127. loadProc(renderer_begin_block, "ltsRendererBeginBlock");
  1128. loadProc(renderer_end_block, "ltsRendererEndBlock");
  1129. loadProc(renderer_abort_block, "ltsRendererAbortBlock");
  1130. loadProc(renderer_get_text_width_a, "ltsRendererGetTextWidthA");
  1131. loadProc(renderer_get_text_width_w, "ltsRendererGetTextWidthW");
  1132. loadProc(renderer_destroy, "ltsRendererDestroy");
  1133. loadProc(font_creator_create, "ltsFontCreatorCreate");
  1134. loadProc(font_creator_get_font_by_name, "ltsFontCreatorGetFontByName");
  1135. loadProc(font_creator_get_font_by_file, "ltsFontCreatorGetFontByFile");
  1136. loadProc(font_creator_get_font_by_stream, "ltsFontCreatorGetFontByStream");
  1137. loadProc(font_creator_destroy, "ltsFontCreatorDestroy");
  1138. loadProc(font_get_post_processor, "ltsFontGetPostProcessor");
  1139. loadProc(font_get_tab_width, "ltsFontGetTabWidth");
  1140. loadProc(font_get_char_spacing, "ltsFontGetCharSpacing");
  1141. loadProc(font_get_line_spacing, "ltsFontGetLineSpacing");
  1142. loadProc(font_get_metric, "ltsFontGetMetric");
  1143. loadProc(font_get_fontname, "ltsFontGetFontname");
  1144. loadProc(font_get_facename, "ltsFontGetFacename");
  1145. loadProc(font_get_stylename, "ltsFontGetStylename");
  1146. loadProc(font_get_fullname, "ltsFontGetFullname");
  1147. loadProc(font_get_copyright, "ltsFontGetCopyright");
  1148. loadProc(font_set_post_processor, "ltsFontSetPostProcessor");
  1149. loadProc(font_set_tab_width, "ltsFontSetTabWidth");
  1150. loadProc(font_set_char_spacing, "ltsFontSetCharSpacing");
  1151. loadProc(font_set_line_spacing, "ltsFontSetLineSpacing");
  1152. loadProc(font_destroy, "ltsFontDestroy");
  1153. loadProc(text_block_get_rect, "ltsTextBlockGetRect");
  1154. loadProc(text_block_get_width, "ltsTextBlockGetWidth");
  1155. loadProc(text_block_get_height, "ltsTextBlockGetHeight");
  1156. loadProc(text_block_get_flags, "ltsTextBlockGetFlags");
  1157. loadProc(text_block_get_top, "ltsTextBlockGetTop");
  1158. loadProc(text_block_get_left, "ltsTextBlockGetLeft");
  1159. loadProc(text_block_get_vert_align, "ltsTextBlockGetVertAlign");
  1160. loadProc(text_block_get_horz_align, "ltsTextBlockGetHorzAlign");
  1161. loadProc(text_block_get_clipping, "ltsTextBlockGetClipping");
  1162. loadProc(text_block_get_color, "ltsTextBlockGetColor");
  1163. loadProc(text_block_get_font, "ltsTextBlockGetFont");
  1164. loadProc(text_block_set_top, "ltsTextBlockSetTop");
  1165. loadProc(text_block_set_left, "ltsTextBlockSetLeft");
  1166. loadProc(text_block_set_vert_align, "ltsTextBlockSetVertAlign");
  1167. loadProc(text_block_set_horz_align, "ltsTextBlockSetHorzAlign");
  1168. loadProc(text_block_set_clipping, "ltsTextBlockSetClipping");
  1169. loadProc(text_block_set_color, "ltsTextBlockSetColor");
  1170. loadProc(text_block_set_font, "ltsTextBlockSetFont");
  1171. loadProc(text_block_get_actual_height, "ltsTextBlockGetActualHeight");
  1172. loadProc(text_block_get_text_width_a, "ltsTextBlockGetTextWidthA");
  1173. loadProc(text_block_get_text_width_w, "ltsTextBlockGetTextWidthW");
  1174. loadProc(text_block_text_out_a, "ltsTextBlockTextOutA");
  1175. loadProc(text_block_text_out_w, "ltsTextBlockTextOutW");
  1176. loadProc(text_block_destroy, "ltsTextBlockDestroy");
  1177. loadProc(image_create, "ltsImageCreate");
  1178. loadProc(image_is_empty, "ltsImageIsEmpty");
  1179. loadProc(image_get_width, "ltsImageGetWidth");
  1180. loadProc(image_get_height, "ltsImageGetHeight");
  1181. loadProc(image_get_line_size, "ltsImageGetLineSize");
  1182. loadProc(image_get_data_size, "ltsImageGetDataSize");
  1183. loadProc(image_get_format, "ltsImageGetFormat");
  1184. loadProc(image_get_data, "ltsImageGetData");
  1185. loadProc(image_get_scanline, "ltsImageGetScanline");
  1186. loadProc(image_get_pixel_at, "ltsImageGetPixelAt");
  1187. loadProc(image_assign, "ltsImageAssign");
  1188. loadProc(image_create_empty, "ltsImageCreateEmpty");
  1189. loadProc(image_load_from_func, "ltsImageLoadFromFunc");
  1190. loadProc(image_resize, "ltsImageResize");
  1191. loadProc(image_fill_color, "ltsImageFillColor");
  1192. loadProc(image_fill_pattern, "ltsImageFillPattern");
  1193. loadProc(image_blend, "ltsImageBlend");
  1194. loadProc(image_blur, "ltsImageBlur");
  1195. loadProc(image_destroy, "ltsImageDestroy");
  1196. loadProc(post_processor_add_range, "ltsPostProcessorAddRange");
  1197. loadProc(post_processor_add_chars, "ltsPostProcessorAddChars");
  1198. loadProc(post_processor_clear_ranges, "ltsPostProcessorClearRanges");
  1199. loadProc(post_processor_execute, "ltsPostProcessorExecute");
  1200. loadProc(post_processor_fill_color_create, "ltsPostProcessorFillColorCreate");
  1201. loadProc(post_processor_fill_pattern_create, "ltsPostProcessorFillPatterCreate");
  1202. loadProc(post_processor_border_create, "ltsPostProcessorBorderCreate");
  1203. loadProc(post_processor_shadow_create, "ltsPostProcessorShadowCreate");
  1204. loadProc(post_processor_custom_create, "ltsPostProcessorCustomCreate");
  1205. loadProc(post_processor_destroy, "ltsPostProcessorDestroy");
  1206. loadProc(char_get_char_code, "ltsCharGetCharCode");
  1207. loadProc(char_get_glyph_metric, "ltsCharGetGlyphMetric");
  1208. loadProc(char_set_glyph_metric, "ltsCharSetGlyphMetric");
  1209. loadProc(initialize, "ltsInitialize");
  1210. loadProc(get_last_error_code, "ltsGetLastErrorCode");
  1211. loadProc(get_last_error_msg, "ltsGetLastErrorMsg");
  1212. loadProc(finalize, "ltsFinalize");
  1213. auto err = initialize();
  1214. if (err != ErrorCode::None)
  1215. throw Exception(std::string("unable to initialize library: ") + get_last_error_msg(), get_last_error_code());
  1216. };
  1217. ~Impl()
  1218. {
  1219. finalize();
  1220. }
  1221. };
  1222. namespace lts
  1223. {
  1224. template <typename T>
  1225. T getFunc(const Library::Impl& impl, Handle handle, ErrorCode (WINAPI * const callback)(Handle, T&))
  1226. {
  1227. T value;
  1228. auto err = callback(handle, value);
  1229. if (err != ErrorCode::None)
  1230. throw Exception(impl.get_last_error_msg(), err);
  1231. return value;
  1232. }
  1233. int getFunc(const Library::Impl& impl, Handle handle, int (WINAPI * const callback)(Handle))
  1234. {
  1235. int value = callback(handle);
  1236. if (value < 0)
  1237. throw Exception(impl.get_last_error_msg(), impl.get_last_error_code());
  1238. return value;
  1239. }
  1240. template<typename T>
  1241. T getFunc(const Library::Impl& impl, Handle handle, T (WINAPI * const callback)(Handle), T invalidValue)
  1242. {
  1243. T value = callback(handle);
  1244. if (value == invalidValue)
  1245. throw Exception(impl.get_last_error_msg(), impl.get_last_error_code());
  1246. return value;
  1247. }
  1248. template <typename T>
  1249. void setFunc(const Library::Impl& impl, Handle handle, ErrorCode (WINAPI * const callback)(Handle, T), const T& value)
  1250. {
  1251. auto err = callback(handle, value);
  1252. if (err != ErrorCode::None)
  1253. throw Exception(impl.get_last_error_msg(), err);
  1254. }
  1255. };
  1256. /* Exception **********************************************************************************************************************/
  1257. inline lts::ErrorCode lts::Exception::getErrorCode() const
  1258. { return _errorCode; }
  1259. inline std::string lts::Exception::getMessage() const
  1260. { return _message; }
  1261. const char* lts::Exception::what() const throw()
  1262. { return _message.c_str(); };
  1263. lts::Exception::Exception(std::string message, ErrorCode errorCode) :
  1264. _message (message),
  1265. _errorCode (errorCode)
  1266. { }
  1267. lts::Exception::~Exception() throw()
  1268. { }
  1269. /* Library ************************************************************************************************************************/
  1270. inline const lts::Library::Impl& lts::Library::getImpl() const
  1271. { return *_impl; };
  1272. inline lts::ErrorCode lts::Library::getLastErrorCode() const
  1273. { return _impl->get_last_error_code(); }
  1274. inline std::string lts::Library::getLastErrorMsg() const
  1275. { return std::string(_impl->get_last_error_msg()); }
  1276. lts::Library::Library(const std::string& libName) :
  1277. _handle (0),
  1278. _impl (NULL)
  1279. {
  1280. _handle = libOpen(libName.c_str());
  1281. if (!_handle)
  1282. throw Exception("unable to open shared library: " + libName, lts::ErrorCode::InvalidLibHandle);
  1283. _impl = new Impl(_handle);
  1284. }
  1285. lts::Library::~Library()
  1286. {
  1287. if (_impl)
  1288. {
  1289. delete _impl;
  1290. _impl = NULL;
  1291. }
  1292. if (_handle)
  1293. {
  1294. libClose(_handle);
  1295. _handle = NULL;
  1296. }
  1297. }
  1298. /* context ************************************************************************************************************************/
  1299. inline lts::ContextHandle lts::Context::getHandle() const
  1300. { return _handle; };
  1301. inline lts::CodePage lts::Context::getCodePage() const
  1302. { return getFunc(_impl, _handle, _impl.context_get_code_page); };
  1303. inline lts::WideChar lts::Context::getDefaultChar() const
  1304. { return getFunc(_impl, _handle, _impl.context_get_default_char); };
  1305. inline void lts::Context::setCodePage(const CodePage value)
  1306. { setFunc(_impl, _handle, _impl.context_set_code_page, value); };
  1307. inline void lts::Context::setDefaultChar(const WideChar value)
  1308. { setFunc(_impl, _handle, _impl.context_set_default_char, value); };
  1309. lts::Context::Context(const Library& library) :
  1310. _handle (NULL),
  1311. _impl (library.getImpl())
  1312. {
  1313. _handle = _impl.context_create();
  1314. if (!_handle)
  1315. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1316. };
  1317. /* char ***************************************************************************************************************************/
  1318. inline lts::CharHandle lts::Char::getHandle() const
  1319. { return _handle; }
  1320. inline lts::WideChar lts::Char::getCharCode() const
  1321. { return getFunc(_impl, _handle, _impl.char_get_char_code); };
  1322. inline lts::GlyphMetric lts::Char::getGlyphMetric() const
  1323. { return getFunc(_impl, _handle, _impl.char_get_glyph_metric); };
  1324. inline void lts::Char::setGlyphMetric(const GlyphMetric& value)
  1325. { setFunc(_impl, _handle, _impl.char_set_glyph_metric, value); };
  1326. lts::Char::Char(const Library::Impl& impl, CharHandle handle) :
  1327. _impl (impl),
  1328. _handle (handle)
  1329. { };
  1330. /* image **************************************************************************************************************************/
  1331. inline lts::ImageHandle lts::Image::getHandle() const
  1332. { return _handle; };
  1333. inline bool lts::Image::getIsEmpty() const
  1334. { return getFunc(_impl, _handle, _impl.image_is_empty); };
  1335. inline int lts::Image::getWidth() const
  1336. { return getFunc(_impl, _handle, _impl.image_get_width); };
  1337. inline int lts::Image::getHeight() const
  1338. { return getFunc(_impl, _handle, _impl.image_get_height); };
  1339. inline int lts::Image::getLineSize() const
  1340. { return getFunc(_impl, _handle, _impl.image_get_line_size); };
  1341. inline int lts::Image::getDataSize() const
  1342. { return getFunc(_impl, _handle, _impl.image_get_data_size); };
  1343. inline lts::Format lts::Image::getFormat() const
  1344. { return getFunc(_impl, _handle, _impl.image_get_format); };
  1345. inline void* lts::Image::getData() const
  1346. { return _impl.image_get_data(_handle); }
  1347. inline void* lts::Image::getScanline(int index) const
  1348. { return _impl.image_get_scanline(_handle, index); }
  1349. bool lts::Image::getPixelAt(int x, int y, Color4f& color) const
  1350. {
  1351. auto err = _impl.image_get_pixel_at(_handle, x, y, color);
  1352. if (err == ErrorCode::InvalidValue)
  1353. return false;
  1354. else if (err == ErrorCode::None)
  1355. return true;
  1356. throw Exception(_impl.get_last_error_msg(), err);
  1357. };
  1358. inline void lts::Image::assign(const Image& image)
  1359. { setFunc(_impl, _handle, _impl.image_assign, image.getHandle()); };
  1360. void lts::Image::createEmpty(Format format, int width, int height)
  1361. {
  1362. auto err = _impl.image_create_empty(_handle, format, width, height);
  1363. if (err != ErrorCode::None)
  1364. throw Exception(_impl.get_last_error_msg(), err);
  1365. };
  1366. void lts::Image::loadFromFunc(LoadCallback callback, void* args)
  1367. {
  1368. LoadArgs la;
  1369. la.callback = callback;
  1370. la.args = args;
  1371. la.image = this;
  1372. _impl.image_load_from_func(_handle, &lts::Image::loadCallback, &la);
  1373. };
  1374. void lts::Image::loadFromFunc(LoadFunction func)
  1375. {
  1376. LoadArgs la;
  1377. la.func = &func;
  1378. la.image = this;
  1379. _impl.image_load_from_func(_handle, &lts::Image::loadCallback, &la);
  1380. };
  1381. void lts::Image::resize(int width, int height, int x, int y)
  1382. {
  1383. auto err = _impl.image_resize(_handle, width, height, x, y);
  1384. if (err != ErrorCode::None)
  1385. throw Exception(_impl.get_last_error_msg(), err);
  1386. };
  1387. void lts::Image::fillColor(const Color4f& color, const ColorChannels& mask, const ImageModes& modes)
  1388. {
  1389. auto err = _impl.image_fill_color(_handle, color, mask, const_cast<ImageMode*>(modes.arr));
  1390. if (err != ErrorCode::None)
  1391. throw Exception(_impl.get_last_error_msg(), err);
  1392. };
  1393. void lts::Image::fillPattern(const Image& pattern, int x, int y, const ColorChannels& mask, const ImageModes& modes)
  1394. {
  1395. auto err = _impl.image_fill_pattern(_handle, pattern.getHandle(), x, y, mask, const_cast<ImageMode*>(modes.arr));
  1396. if (err != ErrorCode::None)
  1397. throw Exception(_impl.get_last_error_msg(), err);
  1398. };
  1399. void lts::Image::blend(const Image& image, int x, int y, BlendCallback callback, void* args)
  1400. {
  1401. BlendArgs ba;
  1402. ba.callback = callback;
  1403. ba.args = args;
  1404. ba.image = this;
  1405. _impl.image_load_from_func(_handle, &lts::Image::loadCallback, &ba);
  1406. };
  1407. void lts::Image::blend(const Image& image, int x, int y, BlendFunction func)
  1408. {
  1409. BlendArgs ba;
  1410. ba.func = &func;
  1411. ba.image = this;
  1412. _impl.image_load_from_func(_handle, &lts::Image::loadFunc, &ba);
  1413. };
  1414. void lts::Image::blur(float horzRad, float horzStr, float vertRad, float vertStr, const ColorChannels& mask)
  1415. {
  1416. auto err = _impl.image_blur(_handle, horzRad, horzStr, vertRad, vertStr, mask);
  1417. if (err != ErrorCode::None)
  1418. throw Exception(_impl.get_last_error_msg(), err);
  1419. };
  1420. lts::Image::Image(const Library::Impl& impl, ImageHandle handle) :
  1421. _impl (impl),
  1422. _handle (handle),
  1423. _ownsHandle (false)
  1424. { };
  1425. lts::Image::Image(const Context& context) :
  1426. _impl (context._impl),
  1427. _handle (NULL),
  1428. _ownsHandle (true)
  1429. {
  1430. _handle = _impl.image_create(context.getHandle());
  1431. if (!_handle)
  1432. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1433. }
  1434. lts::Image::~Image()
  1435. {
  1436. if (_ownsHandle && _handle)
  1437. _impl.image_destroy(_handle);
  1438. }
  1439. void lts::Image::loadCallback(ImageHandle handle, int x, int y, lts::Color4f& pixel, void* args)
  1440. {
  1441. auto la = static_cast<LoadArgs*>(args);
  1442. la->callback(*la->image, x, y, pixel, la->args);
  1443. }
  1444. void lts::Image::loadFunc(ImageHandle handle, int x, int y, lts::Color4f& pixel, void* args)
  1445. {
  1446. auto la = static_cast<LoadArgs*>(args);
  1447. (*la->func)(*la->image, x, y, pixel);
  1448. }
  1449. void lts::Image::blendCallback(ImageHandle handle, lts::Color4f src, lts::Color4f dst, lts::Color4f& result, void* args)
  1450. {
  1451. auto ba = static_cast<BlendArgs*>(args);
  1452. result = ba->callback(*ba->image, src, dst, ba->args);
  1453. }
  1454. void lts::Image::blendFunc(ImageHandle handle, lts::Color4f src, lts::Color4f dst, lts::Color4f& result, void* args)
  1455. {
  1456. auto ba = static_cast<BlendArgs*>(args);
  1457. result = (*ba->func)(*ba->image, src, dst);
  1458. }
  1459. /* post processor *****************************************************************************************************************/
  1460. inline void lts::PostProcessor::setHandle(PostProcessorHandle handle)
  1461. { _handle = handle; };
  1462. void lts::PostProcessor::execute(Char& c, Image& i)
  1463. {
  1464. auto err = _impl.post_processor_execute(_handle, c.getHandle(), i.getHandle());
  1465. if (err != ErrorCode::None)
  1466. throw Exception(_impl.get_last_error_msg(), err);
  1467. }
  1468. lts::PostProcessor::PostProcessor(const Context& context) :
  1469. _impl (context._impl),
  1470. _handle (NULL)
  1471. { };
  1472. inline lts::PostProcessorHandle lts::PostProcessor::getHandle() const
  1473. { return _handle; };
  1474. void lts::PostProcessor::addRange(CharRangeUsage usage, WideChar start, WideChar stop)
  1475. {
  1476. auto err = _impl.post_processor_add_range(_handle, usage, start, stop);
  1477. if (err != ErrorCode::None)
  1478. throw Exception(_impl.get_last_error_msg(), err);
  1479. }
  1480. void lts::PostProcessor::addChars(CharRangeUsage usage, const WideChar* chars)
  1481. {
  1482. auto err = _impl.post_processor_add_chars(_handle, usage, chars);
  1483. if (err != ErrorCode::None)
  1484. throw Exception(_impl.get_last_error_msg(), err);
  1485. }
  1486. void lts::PostProcessor::clearRanges()
  1487. {
  1488. auto err = _impl.post_processor_clear_ranges(_handle);
  1489. if (err != ErrorCode::None)
  1490. throw Exception(_impl.get_last_error_msg(), err);
  1491. }
  1492. lts::PostProcessor::~PostProcessor()
  1493. {
  1494. if (_handle)
  1495. {
  1496. _impl.post_processor_destroy(_handle);
  1497. _handle = NULL;
  1498. }
  1499. }
  1500. /* post processor fill color ******************************************************************************************************/
  1501. inline const lts::Color4f& lts::PostProcessorFillColor::getColor() const
  1502. { return _color; };
  1503. inline const lts::ImageModes& lts::PostProcessorFillColor::getModes() const
  1504. { return _modes; };
  1505. const lts::ColorChannels& lts::PostProcessorFillColor::getChannels() const
  1506. { return _channels; };
  1507. lts::PostProcessorFillColor::PostProcessorFillColor(
  1508. const Context& context,
  1509. const Color4f& color,
  1510. const ImageModes& modes,
  1511. const ColorChannels& channels) :
  1512. PostProcessor (context),
  1513. _color (color),
  1514. _modes (modes),
  1515. _channels (channels)
  1516. {
  1517. auto handle = _impl.post_processor_fill_color_create(context.getHandle(), _color, _modes.arr, _channels);
  1518. if (!handle)
  1519. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1520. setHandle(handle);
  1521. };
  1522. /* post processor fill pattern ****************************************************************************************************/
  1523. inline const lts::Image& lts::PostProcessorFillPattern::getPattern() const
  1524. { return _pattern; };
  1525. inline const lts::Position& lts::PostProcessorFillPattern::getPosition() const
  1526. { return _position; };
  1527. inline const lts::ImageModes& lts::PostProcessorFillPattern::getModes() const
  1528. { return _modes; };
  1529. inline const lts::ColorChannels& lts::PostProcessorFillPattern::getChannels() const
  1530. { return _channels; };
  1531. lts::PostProcessorFillPattern::PostProcessorFillPattern(
  1532. const Context& context,
  1533. const Image& pattern,
  1534. const Position& pos,
  1535. const ImageModes& modes,
  1536. const ColorChannels& channels) :
  1537. PostProcessor (context),
  1538. _pattern (pattern),
  1539. _position (pos),
  1540. _modes (modes),
  1541. _channels (channels)
  1542. {
  1543. auto handle = _impl.post_processor_fill_pattern_create(context.getHandle(), pattern.getHandle(), false, _position, _modes.arr, _channels);
  1544. if (!handle)
  1545. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1546. setHandle(handle);
  1547. };
  1548. /* post processor border **********************************************************************************************************/
  1549. inline float lts::PostProcessorBorder::getWidth() const
  1550. { return _width; };
  1551. inline float lts::PostProcessorBorder::getStrength() const
  1552. { return _strength; };
  1553. inline lts::Color4f lts::PostProcessorBorder::getColor() const
  1554. { return _color; };
  1555. inline bool lts::PostProcessorBorder::getKeepSize() const
  1556. { return _keepSize; };
  1557. lts::PostProcessorBorder::PostProcessorBorder(
  1558. const Context& context,
  1559. float width,
  1560. float strength,
  1561. const Color4f& color,
  1562. bool keepSize) :
  1563. PostProcessor (context),
  1564. _width (width),
  1565. _strength (strength),
  1566. _color (color),
  1567. _keepSize (keepSize)
  1568. {
  1569. auto handle = _impl.post_processor_border_create(context.getHandle(), width, strength, color, keepSize);
  1570. if (!handle)
  1571. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1572. setHandle(handle);
  1573. };
  1574. /* post processor shadow **********************************************************************************************************/
  1575. inline float lts::PostProcessorShadow::getRadius() const
  1576. { return _radius; };
  1577. inline float lts::PostProcessorShadow::getStrength() const
  1578. { return _strength; };
  1579. inline lts::Position lts::PostProcessorShadow::getOffset() const
  1580. { return _offset; };
  1581. inline lts::Color4f lts::PostProcessorShadow::getColor() const
  1582. { return _color; };
  1583. lts::PostProcessorShadow::PostProcessorShadow(
  1584. const Context& context,
  1585. float radius,
  1586. float strength,
  1587. const Position& offset,
  1588. const Color4f& color) :
  1589. PostProcessor (context),
  1590. _radius (radius),
  1591. _strength (strength),
  1592. _offset (offset),
  1593. _color (color)
  1594. {
  1595. auto handle = _impl.post_processor_shadow_create(context.getHandle(), radius, strength, offset, color);
  1596. if (!handle)
  1597. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1598. setHandle(handle);
  1599. }
  1600. /* post processor custom **********************************************************************************************************/
  1601. void lts::PostProcessorCustom::doExecute(Char& c, Image& i)
  1602. { /* DUMMY */ }
  1603. lts::PostProcessorCustom::PostProcessorCustom(const Context& context) :
  1604. PostProcessor(context)
  1605. {
  1606. Library::Impl::PostProcessorData ppd;
  1607. ppd.args = this;
  1608. ppd.execute = &PostProcessorCustom::executeCallback;
  1609. auto handle = _impl.post_processor_custom_create(context.getHandle(), ppd);
  1610. if (!handle)
  1611. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1612. setHandle(handle);
  1613. }
  1614. void lts::PostProcessorCustom::executeCallback(CharHandle charHandle, ImageHandle imageHandle, void* args)
  1615. {
  1616. auto ppc = static_cast<PostProcessorCustom*>(args);
  1617. Char chr(ppc->_impl, charHandle);
  1618. Image img(ppc->_impl, imageHandle);
  1619. ppc->doExecute(chr, img);
  1620. }
  1621. /* post processor list ************************************************************************************************************/
  1622. template<class T>
  1623. void lts::PostProcessorList<T>::doExecute(Char& c, Image& i)
  1624. {
  1625. for (auto& pp : *this)
  1626. pp->execute(c, i);
  1627. }
  1628. template<class T>
  1629. lts::PostProcessorList<T>::PostProcessorList(const Context& context) :
  1630. PostProcessorCustom(context)
  1631. { };
  1632. /* font ***************************************************************************************************************************/
  1633. inline lts::FontHandle lts::Font::getHandle() const
  1634. { return _handle; };
  1635. inline const lts::Font::Names& lts::Font::getNames() const
  1636. { return _names; };
  1637. inline const lts::FontMetric& lts::Font::getMetric() const
  1638. { return _metric; };
  1639. inline lts::PostProcessor* lts::Font::getPostProcessor() const
  1640. { return _postProcessor; };
  1641. inline int lts::Font::getTabWidth() const
  1642. { return getFunc<int>(_impl, _handle, _impl.font_get_tab_width); };
  1643. inline int lts::Font::getCharSpacing() const
  1644. { return getFunc<int>(_impl, _handle, _impl.font_get_char_spacing); };
  1645. inline int lts::Font::getLineSpacing() const
  1646. { return getFunc<float>(_impl, _handle, _impl.font_get_line_spacing); };
  1647. inline void lts::Font::setPostProcessor(PostProcessor* value)
  1648. {
  1649. _postProcessor = value;
  1650. setFunc(_impl, _handle, _impl.font_set_post_processor, (value ? value->getHandle() : NULL));
  1651. };
  1652. inline void lts::Font::setTabWidth(int value)
  1653. { setFunc<int>(_impl, _handle, _impl.font_set_tab_width, value); };
  1654. inline void lts::Font::setCharSpacing(int value)
  1655. { setFunc<int>(_impl, _handle, _impl.font_set_char_spacing, value); };
  1656. inline void lts::Font::setLineSpacing(int value)
  1657. { setFunc<float>(_impl, _handle, _impl.font_set_line_spacing, value); };
  1658. lts::Font::Font(const Library::Impl& impl, FontHandle handle) :
  1659. _impl (impl),
  1660. _handle (handle)
  1661. {
  1662. _metric = getFunc(_impl, _handle, _impl.font_get_metric);
  1663. _names.fontname = std::string(getFunc<const char*>(_impl, _handle, _impl.font_get_fontname, NULL));
  1664. _names.facename = std::string(getFunc<const char*>(_impl, _handle, _impl.font_get_facename, NULL));
  1665. _names.stylename = std::string(getFunc<const char*>(_impl, _handle, _impl.font_get_stylename, NULL));
  1666. _names.fullname = std::string(getFunc<const char*>(_impl, _handle, _impl.font_get_fullname, NULL));
  1667. };
  1668. lts::Font::~Font()
  1669. {
  1670. if (_handle)
  1671. {
  1672. _impl.font_destroy(_handle);
  1673. _handle = NULL;
  1674. }
  1675. }
  1676. /* font creator *******************************************************************************************************************/
  1677. lts::FontCreator::FontCreator(const Context& context) :
  1678. _impl (context._impl),
  1679. _handle (NULL)
  1680. { }
  1681. inline void lts::FontCreator::setHandle(FontCreatorHandle value)
  1682. { _handle = value; }
  1683. inline lts::FontCreatorHandle lts::FontCreator::getHandle() const
  1684. { return _handle; }
  1685. lts::FontPtrU lts::FontCreator::getFontByName(const std::string& fontname, int size, FontStyles styles, AntiAliasing antiAliasing)
  1686. {
  1687. auto handle = _impl.font_creator_get_font_by_name(_handle, fontname.c_str(), size, styles, antiAliasing);
  1688. if (!handle)
  1689. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1690. return FontPtrU(new Font(_impl, handle));
  1691. }
  1692. lts::FontPtrU lts::FontCreator::getFontByFile(const std::string& filename, int size, FontStyles styles, AntiAliasing antiAliasing)
  1693. {
  1694. auto handle = _impl.font_creator_get_font_by_file(_handle, filename.c_str(), size, styles, antiAliasing);
  1695. if (!handle)
  1696. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1697. return FontPtrU(new Font(_impl, handle));
  1698. }
  1699. lts::FontPtrU lts::FontCreator::getFontByStream(std::istream& stream, int size, FontStyles styles, AntiAliasing antiAliasing)
  1700. {
  1701. lts::Library::Impl::StreamData sd;
  1702. sd.args = &stream;
  1703. sd.read = &lts::FontCreator::StreamReadCallback;
  1704. sd.seek = &lts::FontCreator::StreamSeekCallback;
  1705. auto handle = _impl.font_creator_get_font_by_stream(_handle, sd, size, styles, antiAliasing);
  1706. if (!handle)
  1707. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1708. return FontPtrU(new Font(_impl, handle));
  1709. }
  1710. lts::FontCreator::~FontCreator()
  1711. {
  1712. if (_handle)
  1713. {
  1714. _impl.font_creator_destroy(_handle);
  1715. _handle = NULL;
  1716. }
  1717. }
  1718. int lts::FontCreator::StreamReadCallback(void* args, void* buffer, int count)
  1719. {
  1720. std::istream* s = static_cast<std::istream*>(args);
  1721. return s->read(static_cast<char*>(buffer), count).gcount();
  1722. }
  1723. int lts::FontCreator::StreamSeekCallback(void* args, StreamOrigin origin, int offset)
  1724. {
  1725. std::istream* s = static_cast<std::istream*>(args);
  1726. switch(origin)
  1727. {
  1728. case StreamOrigin::Begin:
  1729. return s->seekg(offset, std::ios::beg).tellg();
  1730. case StreamOrigin::Current:
  1731. return s->seekg(offset, std::ios::cur).tellg();
  1732. case StreamOrigin::End:
  1733. return s->seekg(offset, std::ios::end).tellg();
  1734. }
  1735. return s->tellg();
  1736. }
  1737. /* font creator GDI ***************************************************************************************************************/
  1738. lts::FontCreatorGDI::FontCreatorGDI(const Context& context) :
  1739. FontCreator(context)
  1740. {
  1741. auto handle = _impl.font_creator_create(context.getHandle(), FontCreatorType::GDI);
  1742. if (!handle)
  1743. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1744. setHandle(handle);
  1745. }
  1746. /* font creator free type *********************************************************************************************************/
  1747. lts::FontCreatorFreeType::FontCreatorFreeType(const Context& context) :
  1748. FontCreator(context)
  1749. {
  1750. auto handle = _impl.font_creator_create(context.getHandle(), FontCreatorType::FreeType);
  1751. if (!handle)
  1752. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1753. setHandle(handle);
  1754. }
  1755. /* text block *********************************************************************************************************************/
  1756. inline lts::TextBlockHandle lts::TextBlock::getHandle() const
  1757. { return _handle; };
  1758. inline lts::Rect lts::TextBlock::getRect() const
  1759. { return getFunc(_impl, _handle, _impl.text_block_get_rect); };
  1760. inline int lts::TextBlock::getWidth() const
  1761. { return getFunc(_impl, _handle, _impl.text_block_get_width); };
  1762. inline int lts::TextBlock::getHeight() const
  1763. { return getFunc(_impl, _handle, _impl.text_block_get_height); };
  1764. inline lts::BlockFlags lts::TextBlock::getFlags() const
  1765. { return lts::BlockFlags(getFunc(_impl, _handle, _impl.text_block_get_flags)); };
  1766. inline int lts::TextBlock::getTop() const
  1767. { return getFunc(_impl, _handle, _impl.text_block_get_top); };
  1768. inline int lts::TextBlock::getLeft() const
  1769. { return getFunc(_impl, _handle, _impl.text_block_get_left); };
  1770. inline lts::VertAlign lts::TextBlock::getVertAlign() const
  1771. { return getFunc(_impl, _handle, _impl.text_block_get_vert_align); };
  1772. inline lts::HorzAlign lts::TextBlock::getHorzAlign() const
  1773. { return getFunc(_impl, _handle, _impl.text_block_get_horz_align); };
  1774. inline lts::Clipping lts::TextBlock::getClipping() const
  1775. { return getFunc(_impl, _handle, _impl.text_block_get_clipping); };
  1776. inline lts::Color4f lts::TextBlock::getColor() const
  1777. { return getFunc(_impl, _handle, _impl.text_block_get_color); };
  1778. inline lts::Font* lts::TextBlock::getFont() const
  1779. { return _font; };
  1780. inline void lts::TextBlock::setTop(int value)
  1781. { setFunc(_impl, _handle, _impl.text_block_set_top, value); };
  1782. inline void lts::TextBlock::setLeft(int value)
  1783. { setFunc(_impl, _handle, _impl.text_block_set_left, value); };
  1784. inline void lts::TextBlock::setVertAlign(VertAlign value)
  1785. { setFunc(_impl, _handle, _impl.text_block_set_vert_align, value); };
  1786. inline void lts::TextBlock::setHorzAlign(HorzAlign value)
  1787. { setFunc(_impl, _handle, _impl.text_block_set_horz_align, value); };
  1788. inline void lts::TextBlock::setClipping(Clipping value)
  1789. { setFunc(_impl, _handle, _impl.text_block_set_clipping, value); };
  1790. inline void lts::TextBlock::setColor(const Color4f& value)
  1791. { setFunc(_impl, _handle, _impl.text_block_set_color, value); };
  1792. void lts::TextBlock::setFont(Font* font)
  1793. {
  1794. _font = font;
  1795. setFunc<FontHandle>(_impl, _handle, _impl.text_block_set_font, (font ? font->getHandle() : NULL));
  1796. };
  1797. inline int lts::TextBlock::getActualBlockHeight() const
  1798. { return getFunc(_impl, _handle, _impl.text_block_get_actual_height); };
  1799. inline void lts::TextBlock::textOutA(const char* text)
  1800. { setFunc(_impl, _handle, _impl.text_block_text_out_a, text); };
  1801. inline void lts::TextBlock::textOutA(const std::string& text)
  1802. { setFunc(_impl, _handle, _impl.text_block_text_out_a, text.c_str()); };
  1803. inline void lts::TextBlock::textOutW(const WideChar* text)
  1804. { setFunc(_impl, _handle, _impl.text_block_text_out_w, text); };
  1805. inline void lts::TextBlock::textOutW(const std::wstring& text)
  1806. { setFunc(_impl, _handle, _impl.text_block_text_out_w, text.c_str()); };
  1807. int lts::TextBlock::getTextWidthA(const char* text)
  1808. {
  1809. int ret = _impl.text_block_get_text_width_a(_handle, text);
  1810. if (ret < 0)
  1811. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1812. };
  1813. int lts::TextBlock::getTextWidthA(const std::string& text)
  1814. {
  1815. int ret = _impl.text_block_get_text_width_a(_handle, text.c_str());
  1816. if (ret < 0)
  1817. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1818. };
  1819. int lts::TextBlock::getTextWidthW(const WideChar* text)
  1820. {
  1821. int ret = _impl.text_block_get_text_width_w(_handle, text);
  1822. if (ret < 0)
  1823. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1824. };
  1825. int lts::TextBlock::getTextWidthW(const std::wstring& text)
  1826. {
  1827. int ret = _impl.text_block_get_text_width_w(_handle, text.c_str());
  1828. if (ret < 0)
  1829. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1830. };
  1831. lts::TextBlock::TextBlock(const Library::Impl& impl, TextBlockHandle handle) :
  1832. _impl (impl),
  1833. _handle (handle)
  1834. { };
  1835. lts::TextBlock::~TextBlock()
  1836. {
  1837. if (_handle)
  1838. {
  1839. _impl.text_block_destroy(_handle);
  1840. _handle = NULL;
  1841. }
  1842. };
  1843. /* renderer ***********************************************************************************************************************/
  1844. inline void lts::Renderer::setHandle(RendererHandle value)
  1845. { _handle = value; }
  1846. lts::Renderer::Renderer(const Context& context) :
  1847. _impl (context._impl),
  1848. _handle (NULL)
  1849. { }
  1850. inline lts::RendererHandle lts::Renderer::getHandle() const
  1851. { return _handle; }
  1852. lts::TextBlockPtrU lts::Renderer::beginBlock(int top, int left, int width, int height, BlockFlags flags)
  1853. {
  1854. auto handle = _impl.renderer_begin_block(_handle, top, left, width, height, flags);
  1855. if (!handle)
  1856. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1857. return TextBlockPtrU(new TextBlock(_impl, handle));
  1858. }
  1859. inline void lts::Renderer::endBlock(TextBlockPtrU block)
  1860. { if (block) setFunc(_impl, _handle, _impl.renderer_end_block, block->getHandle()); }
  1861. inline void lts::Renderer::abortBlock(TextBlockPtrU block)
  1862. { if (block) setFunc(_impl, _handle, _impl.renderer_abort_block, block->getHandle()); }
  1863. int lts::Renderer::getTextWidthA(const Font& font, const char* text)
  1864. {
  1865. auto ret = _impl.renderer_get_text_width_a(_handle, font.getHandle(), text);
  1866. if (ret < 0)
  1867. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1868. return ret;
  1869. }
  1870. int lts::Renderer::getTextWidthA(const Font& font, const std::string& text)
  1871. {
  1872. auto ret = _impl.renderer_get_text_width_a(_handle, font.getHandle(), text.c_str());
  1873. if (ret < 0)
  1874. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1875. return ret;
  1876. }
  1877. int lts::Renderer::getTextWidthW(const Font& font, const WideChar* text)
  1878. {
  1879. auto ret = _impl.renderer_get_text_width_w(_handle, font.getHandle(), text);
  1880. if (ret < 0)
  1881. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1882. return ret;
  1883. }
  1884. int lts::Renderer::getTextWidthW(const Font& font, const std::wstring& text)
  1885. {
  1886. auto ret = _impl.renderer_get_text_width_w(_handle, font.getHandle(), text.c_str());
  1887. if (ret < 0)
  1888. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1889. return ret;
  1890. }
  1891. lts::Renderer::~Renderer()
  1892. {
  1893. if (_handle)
  1894. {
  1895. _impl.renderer_destroy(_handle);
  1896. _handle = NULL;
  1897. }
  1898. }
  1899. /* renderer OpenGL ****************************************************************************************************************/
  1900. lts::RendererOpenGL::RendererOpenGL(const Context& context, Format format) :
  1901. Renderer(context)
  1902. {
  1903. auto handle = _impl.renderer_create(context.getHandle(), RendererType::OpenGL, format);
  1904. if (!handle)
  1905. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1906. setHandle(handle);
  1907. }
  1908. /* renderer OpenGLES **************************************************************************************************************/
  1909. lts::RendererOpenGLES::RendererOpenGLES(const Context& context, Format format) :
  1910. Renderer(context)
  1911. {
  1912. auto handle = _impl.renderer_create(context.getHandle(), RendererType::OpenGLES, format);
  1913. if (!handle)
  1914. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1915. setHandle(handle);
  1916. }
  1917. /* renderer custom ****************************************************************************************************************/
  1918. void lts::RendererCustom::beginRender()
  1919. { /* DUMMY */ }
  1920. void lts::RendererCustom::endRender()
  1921. { /* DUMMY */ }
  1922. lts::Position lts::RendererCustom::getDrawPos()
  1923. { return _drawPos; }
  1924. void lts::RendererCustom::setDrawPos(const Position& value)
  1925. { _drawPos = value; }
  1926. void lts::RendererCustom::moveDrawPos(const Position& offset)
  1927. { _drawPos.x += offset.x; _drawPos.y += offset.y; }
  1928. void lts::RendererCustom::setColor(const Color4f& color)
  1929. { _color = color; }
  1930. void lts::RendererCustom::render(RenderRef ref, int forcedWidth)
  1931. { /* DUMMY */ }
  1932. lts::RenderRef lts::RendererCustom::createRenderRef(Char& c, const Image& img)
  1933. { return NULL; }
  1934. void lts::RendererCustom::freeRenderRef(RenderRef ref)
  1935. { /* DUMMY */ }
  1936. lts::RendererCustom::RendererCustom(const Context& context, Format format) :
  1937. Renderer(context)
  1938. {
  1939. Library::Impl::RendererCustomData rcd;
  1940. rcd.args = this;
  1941. rcd.beginRender = &RendererCustom::BeginRenderCallback;
  1942. rcd.endRender = &RendererCustom::EndRendererCallback;
  1943. rcd.getDrawPos = &RendererCustom::GetDrawPosCallback;
  1944. rcd.setDrawPos = &RendererCustom::SetDrawPosCallback;
  1945. rcd.moveDrawPos = &RendererCustom::MoveDrawPosCallback;
  1946. rcd.setColor = &RendererCustom::SetColorCallback;
  1947. rcd.render = &RendererCustom::RenderCallback;
  1948. rcd.createRef = &RendererCustom::CreateRefCallback;
  1949. rcd.freeRef = &RendererCustom::FreeRefCallback;
  1950. auto handle = _impl.renderer_create_custom(context.getHandle(), format, rcd);
  1951. if (!handle)
  1952. throw Exception(_impl.get_last_error_msg(), _impl.get_last_error_code());
  1953. setHandle(handle);
  1954. }
  1955. void lts::RendererCustom::BeginRenderCallback(void* args)
  1956. {
  1957. auto rc = static_cast<RendererCustom*>(args);
  1958. rc->beginRender();
  1959. }
  1960. void lts::RendererCustom::EndRendererCallback(void* args)
  1961. {
  1962. auto rc = static_cast<RendererCustom*>(args);
  1963. rc->endRender();
  1964. }
  1965. lts::Position lts::RendererCustom::GetDrawPosCallback(void* args)
  1966. {
  1967. auto rc = static_cast<RendererCustom*>(args);
  1968. return rc->getDrawPos();
  1969. }
  1970. void lts::RendererCustom::SetDrawPosCallback(lts::Position value, void* args)
  1971. {
  1972. auto rc = static_cast<RendererCustom*>(args);
  1973. rc->setDrawPos(value);
  1974. }
  1975. void lts::RendererCustom::MoveDrawPosCallback(lts::Position value, void* args)
  1976. {
  1977. auto rc = static_cast<RendererCustom*>(args);
  1978. rc->moveDrawPos(value);
  1979. }
  1980. void lts::RendererCustom::SetColorCallback(lts::Color4f value, void* args)
  1981. {
  1982. auto rc = static_cast<RendererCustom*>(args);
  1983. rc->setColor(value);
  1984. }
  1985. void lts::RendererCustom::RenderCallback(void* ref, int forcedWidth, void* args)
  1986. {
  1987. auto rc = static_cast<RendererCustom*>(args);
  1988. rc->render(ref, forcedWidth);
  1989. }
  1990. void* lts::RendererCustom::CreateRefCallback(lts::CharHandle charHandle, lts::ImageHandle imageHandle, void* args)
  1991. {
  1992. auto rc = static_cast<RendererCustom*>(args);
  1993. Char chr(rc->_impl, charHandle);
  1994. Image img(rc->_impl, imageHandle);
  1995. return rc->createRenderRef(chr, img);
  1996. }
  1997. void lts::RendererCustom::FreeRefCallback(void* ref, void* args)
  1998. {
  1999. auto rc = static_cast<RendererCustom*>(args);
  2000. return rc->freeRenderRef(ref);
  2001. }
  2002. #endif /* LIB_TEXT_SUITE_HPP */