/gtk2/ext/gtk2/rbgtkprintcontext.c

https://github.com/msakai/ruby-gnome2 · C · 132 lines · 87 code · 19 blank · 26 comment · 0 complexity · d7c5f4906ab1ebeaf3fc2334318e563e MD5 · raw file

  1. /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
  2. /*
  3. * Copyright (C) 2011 Ruby-GNOME2 Project Team
  4. * Copyright (C) 2006 Ruby-GNOME2 Project Team
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301 USA
  20. */
  21. #include "global.h"
  22. #if GTK_CHECK_VERSION(2,10,0)
  23. #define RG_TARGET_NAMESPACE cPrintContext
  24. #define _SELF(s) (GTK_PRINT_CONTEXT(RVAL2GOBJ(s)))
  25. # ifdef HAVE_RB_CAIRO_H
  26. #include <rb_cairo.h>
  27. /* Rendering */
  28. static VALUE
  29. rg_cairo_context(VALUE self)
  30. {
  31. return CRCONTEXT2RVAL(gtk_print_context_get_cairo_context(_SELF(self)));
  32. }
  33. # endif
  34. static VALUE
  35. rg_page_setup(VALUE self)
  36. {
  37. return GOBJ2RVAL(gtk_print_context_get_page_setup(_SELF(self)));
  38. }
  39. static VALUE
  40. rg_width(VALUE self)
  41. {
  42. return rb_float_new(gtk_print_context_get_width(_SELF(self)));
  43. }
  44. static VALUE
  45. rg_height(VALUE self)
  46. {
  47. return rb_float_new(gtk_print_context_get_height(_SELF(self)));
  48. }
  49. static VALUE
  50. rg_dpi_x(VALUE self)
  51. {
  52. return rb_float_new(gtk_print_context_get_dpi_x(_SELF(self)));
  53. }
  54. static VALUE
  55. rg_dpi_y(VALUE self)
  56. {
  57. return rb_float_new(gtk_print_context_get_dpi_y(_SELF(self)));
  58. }
  59. /* Fonts */
  60. static VALUE
  61. rg_pango_fontmap(VALUE self)
  62. {
  63. return GOBJ2RVAL(gtk_print_context_get_pango_fontmap(_SELF(self)));
  64. }
  65. static VALUE
  66. rg_create_pango_context(VALUE self)
  67. {
  68. return GOBJ2RVALU(gtk_print_context_create_pango_context(_SELF(self)));
  69. }
  70. static VALUE
  71. rg_create_pango_layout(VALUE self)
  72. {
  73. return GOBJ2RVALU(gtk_print_context_create_pango_layout(_SELF(self)));
  74. }
  75. /* Needed for preview implementations */
  76. # ifdef HAVE_RB_CAIRO_H
  77. static VALUE
  78. rg_set_cairo_context(VALUE self, VALUE cr, VALUE dpi_x, VALUE dpi_y)
  79. {
  80. gtk_print_context_set_cairo_context(_SELF(self),
  81. RVAL2CRCONTEXT(cr),
  82. NUM2DBL(dpi_x),
  83. NUM2DBL(dpi_y));
  84. return self;
  85. }
  86. # endif
  87. #endif
  88. void
  89. Init_gtk_print_context(void)
  90. {
  91. #if GTK_CHECK_VERSION(2,10,0)
  92. VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(GTK_TYPE_PRINT_CONTEXT,
  93. "PrintContext", mGtk);
  94. /* Rendering */
  95. # ifdef HAVE_RB_CAIRO_H
  96. RG_DEF_METHOD(cairo_context, 0);
  97. # endif
  98. RG_DEF_METHOD(page_setup, 0);
  99. RG_DEF_METHOD(width, 0);
  100. RG_DEF_METHOD(height, 0);
  101. RG_DEF_METHOD(dpi_x, 0);
  102. RG_DEF_METHOD(dpi_y, 0);
  103. /* Fonts */
  104. RG_DEF_METHOD(pango_fontmap, 0);
  105. RG_DEF_METHOD(create_pango_context, 0);
  106. RG_DEF_METHOD(create_pango_layout, 0);
  107. /* Needed for preview implementations */
  108. # ifdef HAVE_RB_CAIRO_H
  109. RG_DEF_METHOD(set_cairo_context, 3);
  110. # endif
  111. G_DEF_SETTERS(RG_TARGET_NAMESPACE);
  112. #endif
  113. }