xftdim 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/extconf.rb +3 -0
- data/ext/xftdim.c +53 -0
- metadata +65 -0
data/ext/extconf.rb
ADDED
data/ext/xftdim.c
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#include <ruby/ruby.h>
|
2
|
+
#include <X11/Xlib.h>
|
3
|
+
#include <X11/Xft/Xft.h>
|
4
|
+
|
5
|
+
XftFont *load_font(char *, Display *);
|
6
|
+
void textdim(char *, int, char *, int *);
|
7
|
+
VALUE rb_cString_xftdim(VALUE, VALUE);
|
8
|
+
|
9
|
+
void Init_xftdim() {
|
10
|
+
rb_define_method(rb_cString, "xftdim", rb_cString_xftdim, 1);
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE
|
14
|
+
rb_cString_xftdim(VALUE self, VALUE font) {
|
15
|
+
int d[2];
|
16
|
+
VALUE dims = rb_ary_new();
|
17
|
+
if (rb_type(font) != T_STRING) {
|
18
|
+
rb_raise(rb_eArgError, "Argument must be a string");
|
19
|
+
}
|
20
|
+
|
21
|
+
rb_funcall(self, rb_intern("encode!"), 1, rb_str_new2("UTF-8"));
|
22
|
+
rb_funcall(font, rb_intern("encode!"), 1, rb_str_new2("UTF-8"));
|
23
|
+
textdim(RSTRING_PTR(self), rb_funcall(self, rb_intern("length"), 0), RSTRING_PTR(font), d);
|
24
|
+
rb_ary_push(dims, INT2FIX(d[0]));
|
25
|
+
rb_ary_push(dims, INT2FIX(d[1]));
|
26
|
+
|
27
|
+
return dims;
|
28
|
+
}
|
29
|
+
|
30
|
+
void
|
31
|
+
textdim(char * string, int len, char * font_name, int * dims) {
|
32
|
+
XftFont *font;
|
33
|
+
Display *dpy;
|
34
|
+
XGlyphInfo extents;
|
35
|
+
|
36
|
+
if (!(dpy = XOpenDisplay(NULL)))
|
37
|
+
rb_raise(rb_eException, "Can't connect to X server %s\n", XDisplayName(NULL));
|
38
|
+
|
39
|
+
font = load_font(font_name, dpy);
|
40
|
+
XftTextExtentsUtf8(dpy, font, (const FcChar8 *) string, len, &extents);
|
41
|
+
dims[0] = extents.width - extents.x;
|
42
|
+
dims[1] = font->height;
|
43
|
+
XCloseDisplay(dpy);
|
44
|
+
}
|
45
|
+
|
46
|
+
XftFont *
|
47
|
+
load_font(char * font_name, Display *dpy) {
|
48
|
+
XftFont *font = NULL;
|
49
|
+
|
50
|
+
if (!(font = XftFontOpenName(dpy, DefaultScreen(dpy), font_name)))
|
51
|
+
rb_raise(rb_eException, "Can't locate '%s`\n", font_name);
|
52
|
+
return font;
|
53
|
+
}
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xftdim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- shura
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-11 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Add a method to String:Class to get width and height of text for given string and xft-font
|
22
|
+
email: shura1991@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions:
|
26
|
+
- ext/extconf.rb
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- ext/extconf.rb
|
31
|
+
- ext/xftdim.c
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/shurizzle/ruby-xftdim
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.7
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Get dimensions of string for a xft-font
|
64
|
+
test_files: []
|
65
|
+
|