Guest User

Untitled

a guest
Jun 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. use Document::Writer;
  5. use Graphics::Color::RGB;
  6. use Graphics::Primitive::Driver::CairoPango;
  7. use Layout::Manager::Compass;
  8. use Layout::Manager::Grid;
  9.  
  10. my $doc = Document::Writer->new;
  11. my $driver = Graphics::Primitive::Driver::CairoPango->new(format => 'pdf');
  12.  
  13. my $black = Graphics::Color::RGB->new(red => 0, green => 0, blue => 0);
  14.  
  15. my @dim = Document::Writer->get_paper_dimensions('letter');
  16. my $p = Document::Writer::Page->new(
  17. color => $black,
  18. # Landscape!
  19. width => $dim[1],
  20. height => $dim[0],
  21. );
  22.  
  23. # Body layout
  24. $p->body->layout_manager(Layout::Manager::Compass->new);
  25.  
  26. # Make the header, pretty much just name
  27. my $header = Graphics::Primitive::Container->new(
  28. layout_manager => Layout::Manager::Compass->new()
  29. );
  30. $header->add_component(make_text_box('Name'), 'e');
  31. $p->body->add_component($header, 'n');
  32.  
  33. # Demography box
  34. my $demo_box = Graphics::Primitive::Container->new(
  35. layout_manager => Layout::Manager::Grid->new(rows => 2, columns => 12)
  36. );
  37.  
  38. $demo_box->add_component(make_text_box('Character Name'), { row => 0, column => 0, width => 2 });
  39. $demo_box->add_component(make_text_box('Level'), { row => 0, column => 2, width => 1 });
  40. $demo_box->add_component(make_text_box('Class'), { row => 0, column => 3, width => 2 });
  41. $demo_box->add_component(make_text_box('Paragon Path'), { row => 0, column => 5, width => 3 });
  42. $demo_box->add_component(make_text_box('Epic Destiny'), { row => 0, column => 8, width => 3 });
  43. $demo_box->add_component(make_text_box('Total XP'), { row => 0, column => 11, width => 1 });
  44.  
  45. $demo_box->add_component(make_text_box('Race'), { row => 1, column => 0, width => 1 });
  46. $demo_box->add_component(make_text_box('Size'), { row => 1, column => 1, width => 1 });
  47. $demo_box->add_component(make_text_box('Age'), { row => 1, column => 2, width => 1 });
  48. $demo_box->add_component(make_text_box('Gender'), { row => 1, column => 3, width => 1 });
  49. $demo_box->add_component(make_text_box('Height'), { row => 1, column => 4, width => 1 });
  50. $demo_box->add_component(make_text_box('Weight'), { row => 1, column => 5, width => 1 });
  51. $demo_box->add_component(make_text_box('Alignment'), { row => 1, column => 6, width => 1 });
  52. $demo_box->add_component(make_text_box('Deity'), { row => 1, column => 7, width => 1 });
  53. $demo_box->add_component(make_text_box('Adventuring Company'), { row => 1, column => 8, width => 3 });
  54. $demo_box->add_component(make_text_box('RPGA Number'), { row => 1, column => 11, width => 1 });
  55.  
  56. $p->body->add_component($demo_box, 'n');
  57.  
  58. my $tboxes = $p->find(sub {
  59. my ($comp, $const) = @_;
  60. return $comp->class eq 'text-label'
  61. });
  62. $tboxes->each(sub {
  63. my ($comp, $const) = @_;
  64.  
  65. $comp->margins->top(14);
  66. $comp->padding->top(2);
  67. $comp->margins->left(5);
  68. $comp->margins->right(5);
  69. $comp->border->color($black);
  70. $comp->border->top->width(1);
  71. $comp->font->size(7);
  72. $comp->font->family('Arial');
  73. });
  74.  
  75. $doc->add_page_break($driver, $p);
  76.  
  77. $doc->draw($driver);
  78. $driver->write('foo.pdf');
  79.  
  80. sub make_text_box {
  81. my ($text) = @_;
  82.  
  83. return Graphics::Primitive::TextBox->new(
  84. text => $text,
  85. color => $black,
  86. class => 'text-label'
  87. );
  88. }
Add Comment
Please, Sign In to add comment