You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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