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.
 
 
 
 
 

1844 lines
79 KiB

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