File: pangoManuals.R

package info (click to toggle)
rgtk2 2.20.24-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 33,456 kB
  • sloc: ansic: 136,438; xml: 18; makefile: 5
file content (180 lines) | stat: -rw-r--r-- 4,828 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# reason: we need to hide the text length parameter
pangoGetLogAttrs <-
function(text, level, language)
{
        text <- as.character(text)
        level <- as.integer(level)
        checkPtrType(language, "PangoLanguage")

        w <- .RGtkCall("S_pango_get_log_attrs", text, level, language)

        return(invisible(w))
}
pangoGlyphStringGetLogicalWidths <-
function(object, text, embedding.level)
{
        checkPtrType(object, "PangoGlyphString")
        text <- as.character(text)
        embedding.level <- as.integer(embedding.level)

        w <- .RGtkCall("S_pango_glyph_string_get_logical_widths", object, text, embedding.level)

        return(w)
}

# reason: removed text length and attrs length parameters
pangoBreak <-
function(text, analysis)
{
        text <- as.character(text)
        checkPtrType(analysis, "PangoAnalysis")

        w <- .RGtkCall("S_pango_break", text, analysis)

        return(invisible(w))
}

# reason: PangoMatrix is a boxed type that needs to be treated as a reference,
# but there is no way to create one from an API function
# This mimics the aliased static initializer in the API.

pangoMatrixInit <-
function()
{
	w <- .RGtkCall("S_pango_matrix_init")
	
	return(w)
}

# Here are some Pango constants
PANGO_SCALE <- 1024
PANGO_SCALE_XX_SMALL <-  (1 / (1.2 * 1.2 * 1.2))
PANGO_SCALE_X_SMALL <- (1 / (1.2 * 1.2))
PANGO_SCALE_SMALL <- (1 / 1.2)
PANGO_SCALE_MEDIUM <- 1
PANGO_SCALE_LARGE <- 1 * 1.2
PANGO_SCALE_X_LARGE <- 1 * 1.2 * 1.2
PANGO_SCALE_XX_LARGE <- 1 * 1.2 * 1.2 * 1.2

# reason: now let's handle the functions where the text length is omitted
pangoLayoutSetMarkupWithAccel <-
function(object, markup, accel.marker)
{
        checkPtrType(object, "PangoLayout")
        markup <- as.character(markup)
        length <- -1
        accel.marker <- as.character(accel.marker)

        w <- .RGtkCall("S_pango_layout_set_markup_with_accel", object, markup, length, accel.marker)

        return(w)
}
pangoParseMarkup <-
function(markup.text, accel.marker, .errwarn = TRUE)
{
        markup.text <- as.character(markup.text)
        length <- -1
        accel.marker <- as.character(accel.marker)

        w <- .RGtkCall("S_pango_parse_markup", markup.text, length, accel.marker)

        w <- handleError(w, .errwarn)
        
        return(w)
}
pangoGlyphStringIndexToX <-
function(object, text, analysis, index, trailing)
{
        checkPtrType(object, "PangoGlyphString")
        text <- as.character(text)
        length <- nchar(text)
        checkPtrType(analysis, "PangoAnalysis")
        index <- as.integer(index)
        trailing <- as.logical(trailing)

        w <- .RGtkCall("S_pango_glyph_string_index_to_x", object, text, length, analysis, index, trailing)

        return(w)
}
pangoGlyphStringXToIndex <-
function(object, text, analysis, x.pos)
{
        checkPtrType(object, "PangoGlyphString")
        text <- as.character(text)
        length <- nchar(text)
        checkPtrType(analysis, "PangoAnalysis")
        x.pos <- as.integer(x.pos)

        w <- .RGtkCall("S_pango_glyph_string_x_to_index", object, text, length, analysis, x.pos)

        return(invisible(w))
}
pangoShape <-
function(text, analysis, glyphs)
{
        text <- as.character(text)
        length <- nchar(text)
        checkPtrType(analysis, "PangoAnalysis")
        checkPtrType(glyphs, "PangoGlyphString")

        w <- .RGtkCall("S_pango_shape", text, length, analysis, glyphs)

        return(w)
}
# reason: var-args, just set aligns/positions for each one
pangoTabArrayNewWithPositions <-
function(size, positions.in.pixels, ...)
{
        size <- as.integer(size)
        positions.in.pixels <- as.logical(positions.in.pixels)
        args <- list(...)
		alignments <- args[seq(1,length(args),by=2)]
		positions <- args[seq(2,length(args),by=2)]
		
		array <- pangoTabArrayNew(size, positions.in.pixels)
		for (i in 1:length(args))
			pangoTabArraySetTab(array, i-1, alignments[[i]], positions[[i]])
        
		return(array)
}

# these are macros that seem simple enough to reimplement in R
# of course, if they change this will also need to be updated

pangoAscent <- function(x)
{
	rect <- as.PangoRectangle(x)
	-rect$y
}
pangoDescent <- function(x)
{
	rect <- as.PangoRectangle(x)
	rect$y + rect$height
}
pangoLbearing <- function(x)
{
	rect <- as.PangoRectangle(x)
	rect$x
}
pangoRbearing <- function(x)
{
	rect <- as.PangoRectangle(x)
	rect$x + rect$width
}

pangoReorderItems <-
function(logical.items)
{
	.notimplemented("wouldn't work automatically due to memory management details and the API says its useless")
}

## version checking ##

boundPangoVersion <- function() {
  as.numeric_version(paste(.RGtkCall("boundPangoVersion"), collapse="."))
}

checkPango <- function(version) {
  .Deprecated("boundPangoVersion() >= version")
  boundPangoVersion() >= version
}