pango 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/ChangeLog +662 -0
  2. data/README +33 -0
  3. data/Rakefile +86 -0
  4. data/extconf.rb +68 -0
  5. data/sample/attribute.rb +82 -0
  6. data/sample/break.rb +26 -0
  7. data/sample/gdk_layout.rb +27 -0
  8. data/sample/glyphstring.rb +61 -0
  9. data/sample/item.rb +35 -0
  10. data/sample/label.rb +23 -0
  11. data/sample/layout.rb +102 -0
  12. data/sample/pango_cairo.rb +66 -0
  13. data/sample/parse.rb +33 -0
  14. data/sample/sample.txt +10 -0
  15. data/sample/script.rb +21 -0
  16. data/src/lib/pango.rb +60 -0
  17. data/src/makeinits.rb +48 -0
  18. data/src/rbpango.c +27 -0
  19. data/src/rbpango.h +97 -0
  20. data/src/rbpangoanalysis.c +197 -0
  21. data/src/rbpangoattribute.c +557 -0
  22. data/src/rbpangoattriterator.c +137 -0
  23. data/src/rbpangoattrlist.c +104 -0
  24. data/src/rbpangocairo.c +229 -0
  25. data/src/rbpangocolor.c +121 -0
  26. data/src/rbpangocontext.c +341 -0
  27. data/src/rbpangocoverage.c +104 -0
  28. data/src/rbpangoengine.c +65 -0
  29. data/src/rbpangofont.c +123 -0
  30. data/src/rbpangofontdescription.c +300 -0
  31. data/src/rbpangofontface.c +71 -0
  32. data/src/rbpangofontfamily.c +74 -0
  33. data/src/rbpangofontmap.c +104 -0
  34. data/src/rbpangofontmetrics.c +85 -0
  35. data/src/rbpangofontset.c +68 -0
  36. data/src/rbpangofontsetsimple.c +53 -0
  37. data/src/rbpangoglyphinfo.c +119 -0
  38. data/src/rbpangoglyphitem.c +129 -0
  39. data/src/rbpangoglyphstring.c +162 -0
  40. data/src/rbpangogravity.c +43 -0
  41. data/src/rbpangoinits.c +71 -0
  42. data/src/rbpangoitem.c +110 -0
  43. data/src/rbpangolanguage.c +88 -0
  44. data/src/rbpangolayout.c +593 -0
  45. data/src/rbpangolayoutiter.c +202 -0
  46. data/src/rbpangolayoutline.c +256 -0
  47. data/src/rbpangologattr.c +107 -0
  48. data/src/rbpangomain.c +213 -0
  49. data/src/rbpangomatrix.c +155 -0
  50. data/src/rbpangorectangle.c +178 -0
  51. data/src/rbpangorenderer.c +204 -0
  52. data/src/rbpangoscript.c +80 -0
  53. data/src/rbpangoscriptiter.c +91 -0
  54. data/src/rbpangotabarray.c +128 -0
  55. data/src/rbpangoversion.h +24 -0
  56. data/test/pango-test-utils.rb +9 -0
  57. data/test/run-test.rb +27 -0
  58. data/test/test-attribute.rb +19 -0
  59. data/test/test-language.rb +7 -0
  60. data/test/test_layout.rb +20 -0
  61. metadata +158 -0
data/sample/layout.rb ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/local/bin/ruby
2
+ =begin
3
+ layout.rb - Ruby/Pango sample script.
4
+
5
+ Copyright (c) 2005 Ruby-GNOME2 Project Team
6
+ This program is licenced under the same licence as Ruby-GNOME2.
7
+
8
+ $Id: layout.rb,v 1.2 2006/06/17 13:36:11 mutoh Exp $
9
+ =end
10
+
11
+ require 'gtk2'
12
+ require 'pp'
13
+
14
+ puts
15
+ puts "Start----------"
16
+ puts
17
+ str = File.readlines("sample.txt").to_s
18
+ context = Gdk::Pango.context
19
+ context.base_dir = Pango::Context::DIRECTION_LTR
20
+ context.language = Pango::Language.new("ja_JP")
21
+ fd = Pango::FontDescription.new("Sans 18")
22
+ font = context.load_font(fd)
23
+ font_map = context.font_map
24
+
25
+ p "context: #{context}"
26
+ p "font_desc: #{fd}"
27
+ p "font: #{font}"
28
+ p "font_map: #{font_map}"
29
+
30
+ puts
31
+ puts "Pango::Layout----------"
32
+ puts
33
+ p layout = Pango::Layout.new(context)
34
+
35
+ layout.set_markup(str)
36
+ layout.font_description = fd
37
+ layout.auto_dir = true
38
+ layout.alignment = Pango::Layout::ALIGN_LEFT
39
+
40
+ p "attributes: #{layout.attributes}"
41
+ p "font_description: #{layout.font_description}"
42
+ p "width: #{layout.width}"
43
+ p "wrap: #{layout.wrap}"
44
+ p "ellipsize: #{layout.ellipsize}"
45
+ p "indent: #{layout.indent}"
46
+ p "spacing: #{layout.spacing}"
47
+ p "justify?: #{layout.justify?}"
48
+ p "auto_dir?: #{layout.auto_dir?}"
49
+ p "alignment: #{layout.alignment.inspect}"
50
+ p "tabs: #{layout.tabs}"
51
+ p "single_paragraph_mode?: #{layout.single_paragraph_mode?}"
52
+ p "size: #{layout.size}"
53
+ p "pixel_size: #{layout.pixel_size}"
54
+ p "line_count: #{layout.line_count}"
55
+
56
+ puts "lines:"
57
+ pp layout.lines
58
+
59
+ puts
60
+ puts "Pango::LayoutIter--------"
61
+ puts
62
+ iter = layout.iter
63
+ p "iter: #{iter}"
64
+ p "index: #{iter.index}"
65
+ p "baseline: #{iter.baseline}"
66
+ p "line: #{iter.line}"
67
+ p "char_extents: #{iter.char_extents}"
68
+ p "cluster_extents: #{iter.cluster_extents}"
69
+ p "run_extents: #{iter.run_extents}"
70
+ p "layout_extents: #{iter.layout_extents}"
71
+ p "line_extents: #{iter.line_extents}"
72
+ p "line_yrange: #{iter.line_yrange}"
73
+
74
+ puts
75
+ puts "Pango::GlyphItem-------"
76
+ puts
77
+ glyph = iter.run
78
+ p "glyph: #{glyph}"
79
+ p "item: #{glyph.item}"
80
+ p "glyphs: #{glyph.glyphs}"
81
+
82
+ puts
83
+ puts "Pango::LayoutLine ----------"
84
+ puts
85
+
86
+ line = iter.line
87
+
88
+ p "line = #{line}"
89
+ p "extents: #{line.extents}"
90
+ p "pixel_extents: #{line.pixel_extents}"
91
+ p "index_to_x: #{line.index_to_x(1, true)}"
92
+ p "x_to_index: #{line.x_to_index(1)}"
93
+ p "x_ranges: #{line.get_x_ranges(0, 2)}"
94
+ p "layout: #{line.layout}"
95
+ p "start_index: #{line.start_index}"
96
+ p "length: #{line.length}"
97
+ p "paragraph_start?: #{line.paragraph_start?}"
98
+ p "resolved_dir: #{line.resolved_dir}"
99
+ puts "runs:"
100
+ pp line.runs
101
+ puts
102
+ puts "End----------"
@@ -0,0 +1,66 @@
1
+ =begin
2
+ cairo.rb - Ruby/Pango with cairo sample script.
3
+
4
+ Copyright (c) 2005 Ruby-GNOME2 Project
5
+ This program is licenced under the same licence as Ruby-GNOME2.
6
+
7
+ $Id: pango_cairo.rb,v 1.1 2005/10/15 07:57:52 mutoh Exp $
8
+ =end
9
+
10
+ require 'pango'
11
+
12
+ unless Pango.cairo_available?
13
+ STDERR.puts "This sample requires Pango 1.0.0 or later and cairo support"
14
+ exit 1
15
+ end
16
+
17
+ filename = ARGV.shift
18
+ filename ||= "cairo.png"
19
+
20
+ RADIUS = 150
21
+ N_WORDS = 10
22
+ FONT = "Sans Bold 27"
23
+
24
+ def draw_text(cr)
25
+ # Center coordinates on the middle of the region we are drawing
26
+ cr.translate(RADIUS, RADIUS);
27
+
28
+ # Create a PangoLayout, set the font and text
29
+ layout = cr.create_pango_layout
30
+
31
+ layout.set_text("Text")
32
+ desc = Pango::FontDescription.new(FONT)
33
+ layout.set_font_description(desc)
34
+
35
+ # Draw the layout N_WORDS times in a circle
36
+ N_WORDS.times do |i|
37
+ angle = (360.0 * i) / N_WORDS;
38
+ cr.save do
39
+ # Gradient from red at angle == 60 to blue at angle == 300
40
+ red = (1 + Math.cos((angle - 60) * Math::PI / 180.0)) / 2
41
+ cr.set_source_rgb(red, 0, 1.0 - red)
42
+ cr.rotate(angle * Math::PI / 180.0)
43
+
44
+ # Inform Pango to re-layout the text with the new transformation
45
+ cr.update_pango_layout(layout)
46
+
47
+ width, height = layout.size
48
+ cr.move_to(-(width.to_f / Pango::SCALE) / 2, -RADIUS)
49
+ cr.show_pango_layout(layout)
50
+ end
51
+ end
52
+ end
53
+
54
+ diameter = 2 * RADIUS
55
+ surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, diameter, diameter)
56
+ cr = Cairo::Context.new(surface)
57
+ cr.set_source_rgb(1.0, 1.0, 1.0)
58
+ cr.rectangle(0, 0, diameter, diameter);
59
+ cr.fill
60
+ draw_text(cr)
61
+
62
+ File.open(filename, "wb") do |f|
63
+ cr.target.write_to_png(f)
64
+ end
65
+ # or
66
+ # cr.target.write_to_png(filename)
data/sample/parse.rb ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ =begin
3
+ parse.rb - Ruby/Pango sample script.
4
+
5
+ Copyright (c) 2002,2003 Ruby-GNOME2 Project Team
6
+ This program is licenced under the same licence as Ruby-GNOME2.
7
+
8
+ $Id: parse.rb,v 1.4 2005/03/22 17:41:29 silicio Exp $
9
+ =end
10
+
11
+ require 'pango'
12
+
13
+ str = File.readlines("sample.txt").to_s
14
+ puts str
15
+ puts "------"
16
+
17
+ attr_list, text, accel_char = Pango.parse_markup(str, '$')
18
+ puts "attr_list = #{attr_list}"
19
+ puts "text = #{text}"
20
+ puts "accel_char = #{accel_char}"
21
+ puts "------"
22
+
23
+ iterator = attr_list.iterator
24
+
25
+ attr_list.each(text) do |iterator, text, start_pos, end_pos|
26
+ puts "range = #{start_pos}, #{end_pos}"
27
+ puts "text = #{text}"
28
+ iterator.get.each do |attr|
29
+ puts "#{attr} = #{attr.value}"
30
+ end
31
+ puts "---"
32
+ end
33
+
data/sample/sample.txt ADDED
@@ -0,0 +1,10 @@
1
+ <u><span foreground="red" size="x-large" style="italic"
2
+ lang="en">Hello World!</span></u> <span background="yellow" lang="ja"
3
+ font_desc="Sans Italic 20" stretch="normal">こんにちわ世界!</span>
4
+
5
+ <span size="xx-large" face="Serif" foreground="#006600" background="#ffffee">
6
+ <span size="larger" underline="double" weight="heavy">Ruby/Pango</span> <span
7
+ rise="10000" variant="normal" weight="heavy">$Ruby-GNOME2</span>
8
+ </span>
9
+
10
+ <span strikethrough="true" size="xx-large" style="oblique" foreground="blue">ABCDEF</span>
data/sample/script.rb ADDED
@@ -0,0 +1,21 @@
1
+ =begin
2
+ script.rb - Ruby/Pango sample script.
3
+
4
+ Copyright (c) 2005 Ruby-GNOME2 Project
5
+ This program is licenced under the same licence as Ruby-GNOME2.
6
+
7
+ $Id: script.rb,v 1.1 2005/09/17 17:09:12 mutoh Exp $
8
+ =end
9
+
10
+ require 'pango'
11
+
12
+ iter = Pango::ScriptIter.new("Helloこんにちはコンニチハ안녕하세요السلام عليكمΕλληνικάவணக்கம்")
13
+ begin
14
+ start_pos, end_pos, script = iter.range
15
+ puts "-----"
16
+ puts "start : #{start_pos}"
17
+ puts "end : #{end_pos}"
18
+ puts "script: #{script.nick}"
19
+ puts "sample_language: #{script.sample_language.to_s}"
20
+ end while iter.next!
21
+
data/src/lib/pango.rb ADDED
@@ -0,0 +1,60 @@
1
+ #
2
+ # pango.rb
3
+ # Copyright(C) 2005, 2009 Ruby-GNOME2 Project.
4
+ #
5
+ # This program is licenced under the same
6
+ # license of Ruby-GNOME2.
7
+ #
8
+
9
+ require 'glib2'
10
+ begin
11
+ begin
12
+ require 'cairo'
13
+ rescue LoadError
14
+ require 'rubygems'
15
+ require 'cairo'
16
+ end
17
+ rescue LoadError
18
+ end
19
+ require 'pango.so'
20
+
21
+ module Pango
22
+ LOG_DOMAIN = "Pango"
23
+
24
+ class AttrList
25
+ def each(text = nil)
26
+ iter = iterator
27
+ begin
28
+ if text
29
+ s, e = iter.range
30
+ yield(iter, text[s, e - s], s, e)
31
+ else
32
+ yield(iter)
33
+ end
34
+ end while iter.next!
35
+ end
36
+ end
37
+
38
+ # [[klass, prefix], ....]]
39
+ targets = [[Layout::Alignment, "ALIGN_"], [AttrScale, "SCALE_"],
40
+ [Coverage::Level, "COVERAGE_"], [Context::Direction, "DIRECTION_"],
41
+ [Layout::WrapMode, "WRAP_"], [FontDescription::FontMask, "FONT_MASK_"],
42
+ [FontDescription::Stretch, "STRETCH_"], [FontDescription::Style, "STYLE_"],
43
+ [FontDescription::Variant, "VARIANT_"], [FontDescription::Weight, "WEIGHT_"],
44
+ [TabArray::TabAlign, "TAB_"],
45
+ [AttrUnderline::Underline, "UNDERLINE_"]]
46
+
47
+ targets << [Script, "SCRIPT_"] if defined? Script
48
+ targets << [Layout::EllipsizeMode, "ELLIPSIZE_"] if defined? Layout::EllipsizeMode
49
+ targets << [Renderer::Part, "PART_"] if defined? Renderer::Part
50
+
51
+ targets.each do |klass, prefix|
52
+ (klass.constants - klass.superclass.constants).each do |name|
53
+ unless klass.const_get(name).is_a? Class
54
+ const_set("#{prefix}#{name}", klass.const_get(name))
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ GLib::Log.set_log_domain(Pango::LOG_DOMAIN)
data/src/makeinits.rb ADDED
@@ -0,0 +1,48 @@
1
+ =begin
2
+ makeinits.rb -
3
+
4
+ $Author: mutoh $
5
+ $Date: 2005/01/28 09:24:45 $
6
+
7
+ Copyright (C) 2002-2005 Masao Mutoh
8
+ =end
9
+
10
+ except_targets = ["Init_pango()"]
11
+
12
+ def print_data(array, type, defs, extern = false)
13
+ if array[type]
14
+ extern_def = "extern void" if extern
15
+ print "##{defs} #{type}\n" if defs
16
+ array[type].each do |val|
17
+ print "#{extern_def} #{val};\n"
18
+ end
19
+ print "#endif\n" if defs
20
+ end
21
+ end
22
+
23
+ inits = Hash.new
24
+
25
+ while gets
26
+ if ~ /^(Init_.*\(.*\))(.*)/
27
+ init = $1
28
+ unless except_targets.include?(init)
29
+ flag = $2
30
+ if flag.size > 0
31
+ if flag =~ /\/\*\s*(\w*)\s*\*\//
32
+ inits[$1] = Array.new unless inits[$1]
33
+ inits[$1] << init
34
+ end
35
+ else
36
+ inits[""] = Array.new unless inits[""]
37
+ inits[""] << init
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ print_data(inits, "", nil, true)
44
+
45
+ puts "void Init_pango_inits()\n"
46
+ puts "{\n"
47
+ print_data(inits, "", nil)
48
+ puts "}\n"
data/src/rbpango.c ADDED
@@ -0,0 +1,27 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbpango.c -
5
+
6
+ $Author: mutoh $
7
+ $Date: 2005/09/28 18:04:21 $
8
+
9
+ Copyright (C) 2002-2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbpango.h"
13
+
14
+ VALUE mPango;
15
+
16
+ void
17
+ Init_pango()
18
+ {
19
+ mPango = rb_define_module("Pango");
20
+
21
+ rb_define_const(mPango, "BUILD_VERSION",
22
+ rb_ary_new3(3,
23
+ INT2FIX(PANGO_MAJOR_VERSION),
24
+ INT2FIX(PANGO_MINOR_VERSION),
25
+ INT2FIX(PANGO_MICRO_VERSION)));
26
+ Init_pango_inits();
27
+ }
data/src/rbpango.h ADDED
@@ -0,0 +1,97 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbpango.h -
5
+
6
+ $Author: ktou $
7
+ $Date: 2005/10/05 11:16:26 $
8
+
9
+ Copyright (C) 2002-2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "ruby.h"
13
+ #define PANGO_ENABLE_ENGINE
14
+ #define PANGO_ENABLE_BACKEND
15
+ #include <pango/pango.h>
16
+
17
+ #define RBPANGO_MAJOR_VERSION 0
18
+ #define RBPANGO_MINOR_VERSION 20
19
+ #define RBPANGO_MICRO_VERSION 0
20
+
21
+ #if HAVE_FREETYPE2
22
+ #include <pango/pangofc-font.h>
23
+ #endif
24
+
25
+ #include "rbgobject.h"
26
+ #include "rbpangoversion.h"
27
+
28
+ #if PANGO_CHECK_VERSION(1,10,0)
29
+ #include <pango/pangocairo.h>
30
+ # if HAVE_RB_CAIRO_H
31
+ #include <rb_cairo.h>
32
+ # endif
33
+ #endif
34
+
35
+ #if defined(G_PLATFORM_WIN32) && !defined(RUBY_PANGO_STATIC_COMPILATION)
36
+ # ifdef RUBY_PANGO_COMPILATION
37
+ # define RUBY_PANGO_VAR __declspec(dllexport)
38
+ # else
39
+ # define RUBY_PANGO_VAR extern __declspec(dllimport)
40
+ # endif
41
+ #else
42
+ # define RUBY_PANGO_VAR extern
43
+ #endif
44
+
45
+ extern void Init_pango_inits();
46
+ RUBY_PANGO_VAR VALUE mPango;
47
+
48
+ #ifndef PANGO_TYPE_ITEM
49
+ #define PANGO_TYPE_ITEM (pango_item_get_type())
50
+ #endif
51
+ #define PANGO_TYPE_ANALYSIS (pango_analysis_get_type())
52
+ #define PANGO_TYPE_LOG_ATTR (pango_log_attr_get_type())
53
+ #ifndef PANGO_TYPE_LAYOUT_ITER
54
+ #define PANGO_TYPE_LAYOUT_ITER (pango_layout_iter_get_type())
55
+ #endif
56
+ #ifndef PANGO_TYPE_LAYOUT_LINE
57
+ #define PANGO_TYPE_LAYOUT_LINE (pango_layout_line_get_type())
58
+ #endif
59
+ #define PANGO_TYPE_RECTANGLE (pango_rectangle_get_type())
60
+ #define PANGO_TYPE_ATTR_ITERATOR (pango_attr_iter_get_type())
61
+ #define PANGO_TYPE_COVERAGE (pango_coverage_get_type())
62
+ #define PANGO_TYPE_GLYPH_INFO (pango_glyph_info_get_type())
63
+ #ifndef PANGO_TYPE_GLYPH_ITEM
64
+ # define PANGO_TYPE_GLYPH_ITEM (pango_glyph_item_get_type())
65
+ #endif
66
+
67
+ #if PANGO_CHECK_VERSION(1,4,0)
68
+ #define PANGO_TYPE_SCRIPT_ITER (pango_script_iter_get_type())
69
+ #endif
70
+
71
+ #define ATTR2RVAL(attr) (pango_make_attribute(attr))
72
+ #define RVAL2ATTR(attr) (pango_get_attribute(attr))
73
+ #define ATTRTYPE2CLASS(attr_type) (pango_get_attribute_klass(attr_type))
74
+ #define RBPANGO_ADD_ATTRIBUTE(type, klass) (pango_add_attribute(type, klass))
75
+
76
+ extern VALUE pango_make_attribute(PangoAttribute* attr);
77
+ extern PangoAttribute* pango_get_attribute(VALUE attr);
78
+
79
+ extern GType pango_item_get_type();
80
+ extern GType pango_analysis_get_type();
81
+ extern GType pango_log_attr_get_type();
82
+ extern GType pango_layout_iter_get_type();
83
+ extern GType pango_layout_line_get_type();
84
+ extern GType pango_rectangle_get_type();
85
+ extern GType pango_attr_iter_get_type();
86
+ extern GType pango_coverage_get_type();
87
+ extern GType pango_glyph_info_get_type();
88
+ #ifndef HAVE_PANGO_GLYPH_ITEM_GET_TYPE
89
+ extern GType pango_glyph_item_get_type();
90
+ #endif
91
+
92
+ #if PANGO_CHECK_VERSION(1,4,0)
93
+ extern GType pango_script_iter_get_type();
94
+ #endif
95
+
96
+ extern VALUE pango_get_attribute_klass(VALUE attr_type);
97
+ extern void pango_add_attribute(int attr_type, VALUE klass);