class CooCoo::DataSources::Xournal::TrainingDocument::DocumentMaker
Attributes
cells_per_example[R]
columns[R]
page_height[R]
page_width[R]
rows[R]
Public Class Methods
new(training_doc, columns, rows, cells_per_example, page_width, page_height)
click to toggle source
# File lib/coo-coo/data_sources/xournal/training_document/document_maker.rb, line 14 def initialize(training_doc, columns, rows, cells_per_example, page_width, page_height) @doc = training_doc @columns = columns @rows = rows @cells_per_example = cells_per_example @page_width = page_width @page_height = page_height end
Public Instance Methods
make_cell(layer, label, strokes, x, y, grid_w, grid_h)
click to toggle source
# File lib/coo-coo/data_sources/xournal/training_document/document_maker.rb, line 33 def make_cell(layer, label, strokes, x, y, grid_w, grid_h) layer.add_text(Text.new(label, x + 1, y + 1, 12, 'black', 'Serif')) strokes.each do |stroke| layer.add_stroke(stroke.scale(grid_w, grid_h, grid_w).translate(x, y)) end end
make_cells(examples, grid_w, grid_h)
click to toggle source
# File lib/coo-coo/data_sources/xournal/training_document/document_maker.rb, line 40 def make_cells(examples, grid_w, grid_h) layer = Layer.new examples = examples.collect { |e| e.each_set.collect { |s| [ e.label, s ] } + Array.new(@cells_per_example - e.size, [ e.label, [] ]) }.flatten(1) examples.each_slice(@columns).with_index do |row, y| row.each_with_index do |(label, strokes), x| make_cell(layer, label, strokes, x * grid_w, y * grid_h, grid_w, grid_h) end end layer end
make_document()
click to toggle source
# File lib/coo-coo/data_sources/xournal/training_document/document_maker.rb, line 23 def make_document Document.new do |d| @doc.each_example.each_slice(@columns * @rows / @cells_per_example).with_index do |labels, page_num| d.add_page(make_page(labels, page_num)) end d.pages.first.layers.last.add_text(Text.new("#{META_LABEL} #{VERSION}: #{@columns} #{@rows} #{@cells_per_example}", 0, @page_height - 14, 12, 'gray')) end end
make_grid(grid_w, grid_h)
click to toggle source
# File lib/coo-coo/data_sources/xournal/training_document/document_maker.rb, line 58 def make_grid(grid_w, grid_h) grid_layer = Layer.new (1...@rows).each do |y| (1...@columns).each do |x| grid_layer.add_stroke(Stroke.new('pen', GRID_COLOR). add_sample(x * grid_w, 0). add_sample(x * grid_w, @page_height)) end grid_layer.add_stroke(Stroke.new('pen', GRID_COLOR). add_sample(0, y * grid_h). add_sample(@page_width, y * grid_h)) end grid_layer end
make_page(examples, page_num)
click to toggle source
# File lib/coo-coo/data_sources/xournal/training_document/document_maker.rb, line 76 def make_page(examples, page_num) grid_w = @page_width / @columns grid_h = @page_height / @rows Page.new(@page_width, @page_height). add_layer(make_grid(grid_w, grid_h)). add_layer(make_cells(examples, grid_w, grid_h)) end