-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathpango-cairo.js
More file actions
26 lines (22 loc) · 801 Bytes
/
pango-cairo.js
File metadata and controls
26 lines (22 loc) · 801 Bytes
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
/*
* pango-cairo.js
*/
const gi = require('../')
const Gtk = gi.require('Gtk', '3.0')
const Cairo = gi.require('cairo')
const Pango = gi.require('Pango')
const PangoCairo = gi.require('PangoCairo')
gi.startLoop()
Gtk.init()
const surface = new Cairo.ImageSurface(Cairo.Format.RGB24, 300, 300)
const cr = new Cairo.Context(surface)
const fd = Pango.fontDescriptionFromString('Fantasque Sans Mono 16')
const layout = PangoCairo.createLayout(cr)
layout.setFontDescription(fd)
layout.setAlignment(Pango.Alignment.LEFT)
layout.setMarkup('<span font_weight="bold">A</span>')
const [boldWidth, boldHeight] = layout.getSize()
layout.setMarkup('<span>A</span>')
const pixels = layout.getPixelSize()
const [normalWidth, normalHeight] = layout.getSize()
console.log({ fd, pixels, normalWidth, boldWidth })