Class: GTK::Webkit

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk_webkit_pdf.rb,
ext/gtk_webkit_pdf/webkit.c

Constant Summary collapse

VERSION =
"0.0.2.2"
CONTENT =
0
FILEPATH =
1
HTTP_URI =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, format, options = {}) ⇒ Webkit

Returns a new instance of Webkit.

Raises:



17
18
19
20
21
22
# File 'lib/gtk_webkit_pdf.rb', line 17

def initialize(source, format, options = {})
  @source  = source
  @format  = format
  @options = { :mime_type => 'text/html', :encoding => 'UTF-8' }.merge(options)
  raise WebkitError, 'format should be 0 or 1 or 2' unless [CONTENT, FILEPATH, HTTP_URI].member?(@format)
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



15
16
17
# File 'lib/gtk_webkit_pdf.rb', line 15

def format
  @format
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/gtk_webkit_pdf.rb', line 15

def options
  @options
end

#sourceObject

Returns the value of attribute source.



15
16
17
# File 'lib/gtk_webkit_pdf.rb', line 15

def source
  @source
end

Instance Method Details

#generate_pdfObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'ext/gtk_webkit_pdf/webkit.c', line 15

static VALUE c_generate_pdf(VALUE self) {
  VALUE source, content;
  WEBKIT_PTR(self);  

  webkit -> webkit_webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
  source = rb_iv_get(self, "@source");

  switch(NUM2INT(rb_iv_get(self, "@format"))) {
    case 0:
      webkit_web_view_load_string(webkit -> webkit_webview, StringValuePtr(source), NULL, NULL, "file://");
      break;
    case 1:
      content = rb_funcall(self, rb_intern("source_content"), 0, 0);
      webkit_web_view_load_html_string(webkit -> webkit_webview, StringValuePtr(content), "file://");
      break;
    case 2:
      webkit_web_view_load_uri(webkit -> webkit_webview, StringValuePtr(source));
      break;
  }
  g_signal_connect(webkit -> webkit_webview, "load-finished", G_CALLBACK(webkit_load_finished), (void *)self);
  gtk_main();
  return webkit -> printer;
}

#gtk_printerObject



24
25
26
# File 'lib/gtk_webkit_pdf.rb', line 24

def gtk_printer
  @gtk_printer ||= generate_pdf
end