skrift-x11 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a086ab34c955c628b9b32640d98e26415a2e6766e9a784797893b6c8ef7473b0
4
- data.tar.gz: 89a0ea4e3ee0cf221037e6c951d746c63f00140dd775f1b332cb0d7afdc52c67
3
+ metadata.gz: 92507a6b036b8ab2eb0145017a938019111e2ea17c4e001a693529d2518876f3
4
+ data.tar.gz: 2da4b5247c4e4b085a4f4591594d09f69f2f35a93c7fe43210b68f7efbfe3798
5
5
  SHA512:
6
- metadata.gz: 8cf85e533b7d29eb13e993842a83a09bd3eaf7322fe41d93d5290637788d5bd944a90dd96f3f21f618edf2d03998f9667f7c403621470622fd552d72f6d039be
7
- data.tar.gz: e07c349839802875a8d73f13a0dd2daa3beb76c12f52677f34a7a5f5bdd76aab8acdb38dc5c5c59e5612aad1ae2716ba7ffe223a86b4ca63eebae5fde1eae21d
6
+ metadata.gz: 8bac35a07d623a9f27539ec68d2a2cc4eb2cc906e788660a7cbea25323d55ff30ada7ac1474f92c7caa4b8c92a50a509bf6eaf25550c5e04d6e273a13aebe15f
7
+ data.tar.gz: c35c1e39c5b5ef7daf70257dc14e0930ac70607e78b6bc8397563964377d8e090b4472162fbbb061c05c584553ae6d0b7e937e7d3ecc156f534b6eed518c41e5
data/example.rb CHANGED
@@ -7,61 +7,49 @@ require 'pp'
7
7
 
8
8
  Bundler.setup(:default, :development)
9
9
 
10
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
- $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ #$LOAD_PATH.unshift(File.dirname(__FILE__))
12
12
 
13
13
  require 'skrift/x11'
14
14
 
15
- $dpy = dpy = display = X11::Display.new
15
+ dpy = display = X11::Display.new
16
16
  screen = dpy.screens.first
17
+ visual = dpy.find_visual(0, 32).visual_id
18
+ #cmap = dpy.create_colormap(0, screen.root, visual)
17
19
 
18
- # Transparency: Check
19
- # https://stackoverflow.com/questions/13395179/empty-or-transparent-window-with-xlib-showing-border-lines-only/13397150#13397150
20
+ p visual
21
+ #p cmap
20
22
 
21
- # FIXME: Hack; see XFindVisualMatch
22
- visual = 123
23
-
24
- cmap = $dpy.create_colormap(0, screen.root, visual)
25
-
26
- wid = display.new_id
27
- $dpy.create_window(
28
- 32,
29
- wid, screen.root,
30
- 0, 0, # x,y
23
+ wid = dpy.create_window(
24
+ 0, 0, # x,y
31
25
  1000, 600, # w,h
32
- 0,
33
- X11::Form::InputOutput,
34
- visual, #X11::Form::CopyFromParent -- Must be provided if e.g. depth is different than root.
35
- X11::Form::CWBackPixel | X11::Form::CWBorderPixel |
36
- X11::Form::CWEventMask | X11::Form::CWColorMap,
37
- [0x00000000, # ARGB background
38
- 0x0, # Border pixel; Necessary when depth != screen.root_depth
39
- X11::Form::SubstructureNotifyMask |
40
- X11::Form::StructureNotifyMask | ## Move
41
- X11::Form::ExposureMask |
42
- X11::Form::KeyPressMask |
43
- X11::Form::ButtonPressMask,
44
- cmap # Colormap. Necessary when depth != screen.root_depth
45
- ]
26
+ visual: visual,
27
+ values: {
28
+ X11::Form::CWBackPixel => 0, # ARGB background
29
+ X11::Form::CWBorderPixel => 0, # Needed in case window depth != screen.root_depth
30
+ X11::Form::CWEventMask =>
31
+ (X11::Form::SubstructureNotifyMask |
32
+ X11::Form::StructureNotifyMask |
33
+ X11::Form::ExposureMask |
34
+ X11::Form::KeyPressMask |
35
+ X11::Form::ButtonPressMask)#,
36
+ # X11::Form::CWColorMap => cmap # Needed for same reason as borderpixel
37
+ }
46
38
  )
39
+ p wid
47
40
 
48
41
  dpy.map_window(wid) # Window won't be visible until this
49
42
 
50
43
  # A "picture" object for us to draw in the window with.
51
44
  fmt = dpy.render_find_visual_format(visual)
45
+ p fmt
52
46
  $pic = dpy.render_create_picture(wid, fmt)
53
47
 
54
- # The easy way
55
- #$fgpic = dpy.render_create_solid_fill(0xffff,0xffff,0,0)
56
-
57
-
58
- $gc = dpy.create_gc(wid, foreground: 0xffff0000)
59
-
60
- puts "Main loop"
48
+ gc = dpy.create_gc(wid, foreground: 0xffff0000)
61
49
 
62
- $f = Font.load("resources/FiraGO-Regular_extended_with_NotoSansEgyptianHieroglyphs-Regular.ttf")
50
+ f = Font.load("resources/FiraGO-Regular_extended_with_NotoSansEgyptianHieroglyphs-Regular.ttf")
63
51
 
64
- $skrift = Skrift::X11::Glyphs.new($dpy, $f, x_scale: 40, y_scale: 40)
52
+ $skrift = Skrift::X11::Glyphs.new(dpy, f, x_scale: 40, y_scale: 40)
65
53
 
66
54
  def redraw(dpy, wid, gc)
67
55
  dpy.poly_fill_rectangle(wid, gc, [X11::Form::Rectangle.new(20,45, 400, 400)])
@@ -74,9 +62,9 @@ end
74
62
  loop do
75
63
  pkt = display.next_packet
76
64
  if pkt
77
- #puts pkt.inspect[0..200]
65
+ puts pkt.inspect[0..200]
78
66
  #raise "Error" if pkt.is_a?(X11::Form::Error)
79
- redraw(display, wid, $gc) if pkt.is_a?(X11::Form::Expose)
67
+ redraw(display, wid, gc) if pkt.is_a?(X11::Form::Expose)
80
68
 
81
69
  if pkt.is_a?(X11::Form::KeyPress)
82
70
  # lookup_keysym(dpy,pkt)
@@ -20,6 +20,7 @@ module Skrift
20
20
 
21
21
  @glyphcache = {}
22
22
  @colcache = {}
23
+ @chcache = {}
23
24
 
24
25
  @lm = @sft.lmetrics
25
26
 
@@ -60,6 +61,7 @@ module Skrift
60
61
 
61
62
 
62
63
  def cache_glyph(gid, baseline)
64
+ return if gid.nil?
63
65
  mtx = @sft.gmetrics(gid)
64
66
 
65
67
  # FIXME: Not sure what to do if mtx.nil? here.
@@ -103,7 +105,9 @@ module Skrift
103
105
  def map_glyphs(str)
104
106
  # FIXME: Should probably cache by character rather than
105
107
  # glyph
106
- str.to_s.each_char.map { |ch| @sft.lookup(ch.ord) }
108
+ str.to_s.each_char.map do |ch|
109
+ @chcache[ch] ||= @sft.lookup(ch.ord).to_i
110
+ end
107
111
  end
108
112
 
109
113
  def cache_glyphs(gl)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Skrift
4
4
  module X11
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skrift-x11
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vidar Hokstad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-25 00:00:00.000000000 Z
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: skrift