Context.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "mupdf/fitz.h"
  2. #include "mupdf/pdf.h"
  3. using namespace System;
  4. using namespace System::Runtime::InteropServices;
  5. using namespace System::Threading;
  6. #ifndef __CONTEXT
  7. #define __CONTEXT
  8. namespace MuPDF {
  9. #pragma warning( push )
  10. #pragma warning( disable : 4091 )
  11. typedef ref class Document;
  12. typedef ref class Colorspace;
  13. typedef enum class ColorspaceKind;
  14. typedef ref class Pixmap;
  15. typedef value struct BBox;
  16. // in mupdf_load_system_font.c
  17. extern "C" void install_load_windows_font_funcs(fz_context* ctx);
  18. #pragma warning (pop)
  19. public ref class Context : IDisposable {
  20. public:
  21. ~Context() {
  22. ReleaseHandle();
  23. }
  24. static property Context^ Instance {
  25. Context^ get();
  26. }
  27. /// <summary>
  28. /// Gets or sets render anti-alias level. Valid values are ranged [0, 8].
  29. /// </summary>
  30. property int AntiAlias {
  31. int get() { return fz_aa_level(_context); }
  32. void set(int value) { fz_set_aa_level(_context, value); }
  33. }
  34. property int TextAntiAlias {
  35. int get() { return fz_text_aa_level(_context); }
  36. void set(int value) { fz_set_text_aa_level(_context, value); }
  37. }
  38. Document^ OpenDocument(String^ filePath);
  39. Colorspace^ GetColorspace(ColorspaceKind kind);
  40. Pixmap^ CreatePixmap(ColorspaceKind colorspace, int width, int height);
  41. Pixmap^ CreatePixmap(ColorspaceKind colorspace, BBox box);
  42. internal:
  43. static property fz_context* Ptr {
  44. fz_context* get() { return Instance->_context; }
  45. }
  46. protected:
  47. !Context() {
  48. ReleaseHandle();
  49. }
  50. private:
  51. fz_context* _context;
  52. bool _disposed;
  53. initonly bool _isCloned;
  54. static Context^ MakeMainContext();
  55. static Context^ _MainInstance = MakeMainContext();
  56. [System::ThreadStaticAttribute]
  57. static Context^ _Instance = _MainInstance;
  58. Context(fz_context* ctx, bool isCloned) : _context(ctx), _isCloned(isCloned) {
  59. if (!ctx) {
  60. throw gcnew InvalidOperationException("fz_context is null");
  61. }
  62. install_load_windows_font_funcs(ctx);
  63. fz_register_document_handlers(ctx);
  64. }
  65. void ReleaseHandle();
  66. fz_colorspace* GetFzColorspace(ColorspaceKind kind);
  67. };
  68. };
  69. #endif // !__CONTEXT