| 1 |
--------------------------------------------------- |
| 2 |
-- The big... Ada Bar Codes Demo (ABCD :-) ) ! -- |
| 3 |
--------------------------------------------------- |
| 4 |
|
| 5 |
with Ada.Streams.Stream_IO, |
| 6 |
Ada.Text_IO; |
| 7 |
|
| 8 |
with Bar_Codes, Bar_Codes_Media; |
| 9 |
|
| 10 |
procedure Bar_Codes_Demo is |
| 11 |
|
| 12 |
-- SVG files (bar_code_128.svg, dm_code.svg, qr_code_l.svg) can be viewed |
| 13 |
-- directly in a Web browser. |
| 14 |
-- |
| 15 |
-- PDF snippets need to be included into a PDF document. |
| 16 |
-- For instance, use Insert_Graphics_PDF_Code of PDF_Out, http://apdf.sf.net/ |
| 17 |
-- |
| 18 |
-- PBM images demonstrate output as raster graphics. This could be another image |
| 19 |
-- format, or anything else involving pixels, like a screen, a printer, etc. |
| 20 |
-- |
| 21 |
-- PNG images demonstrate output as raster graphics for the ubiquitous PNG format. |
| 22 |
-- |
| 23 |
use Ada.Text_IO; |
| 24 |
svg, pdf, pbm : File_Type; |
| 25 |
|
| 26 |
package SIO renames Ada.Streams.Stream_IO; |
| 27 |
png : SIO.File_Type; |
| 28 |
|
| 29 |
procedure SVG_Header is |
| 30 |
-- NB: the SVG file can be viewed without this header. |
| 31 |
begin |
| 32 |
Put_Line (svg, "<?xml version=""1.0"" encoding=""UTF-8""?>"); |
| 33 |
Put_Line (svg, "<!DOCTYPE svg"); |
| 34 |
Put_Line (svg, " PUBLIC '-//W3C//DTD SVG 1.1//EN'"); |
| 35 |
Put_Line (svg, " 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>"); |
| 36 |
end SVG_Header; |
| 37 |
|
| 38 |
prefix : constant String := "Hello from " & Bar_Codes.title; |
| 39 |
hello_short : constant String := prefix & "! How's life?"; |
| 40 |
hello_long : constant String := prefix & " ( " & Bar_Codes.web & " ) ! My number is: 1234567890"; |
| 41 |
|
| 42 |
procedure Demo_Code_128 is |
| 43 |
use Bar_Codes, Bar_Codes_Media; |
| 44 |
begin |
| 45 |
Create (svg, Out_File, "bar_code_128.svg"); |
| 46 |
SVG_Header; |
| 47 |
Put_Line (svg, SVG_Bar_Code (Code_128, 57.0, 23.0, "mm", hello_short)); |
| 48 |
Close (svg); |
| 49 |
-- |
| 50 |
Create (pdf, Out_File, "bar_code_128_pdf.txt"); |
| 51 |
Put_Line (pdf, PDF_Bar_Code (Code_128, (150.0, 320.0, 600.0, 50.0), hello_short)); |
| 52 |
Close (pdf); |
| 53 |
-- |
| 54 |
Create (pbm, Out_File, "bar_code_128.pbm"); |
| 55 |
Put_Line (pbm, PBM_Bar_Code (Code_128, 2, 100, hello_short)); |
| 56 |
Close (pbm); |
| 57 |
-- |
| 58 |
SIO.Create (png, SIO.Out_File, "bar_code_128.png"); |
| 59 |
PNG_Bar_Code (Code_128, 2, 100, hello_short, SIO.Stream (png).all); |
| 60 |
SIO.Close (png); |
| 61 |
end Demo_Code_128; |
| 62 |
|
| 63 |
procedure Demo_MSI is |
| 64 |
use Bar_Codes, Bar_Codes_Media; |
| 65 |
begin |
| 66 |
SIO.Create (png, SIO.Out_File, "bar_code_msi.png"); |
| 67 |
PNG_Bar_Code (Code_MSI, 2, 100, "12345678901", SIO.Stream (png).all); |
| 68 |
SIO.Close (png); |
| 69 |
end Demo_MSI; |
| 70 |
|
| 71 |
procedure Demo_UPCA is |
| 72 |
use Bar_Codes, Bar_Codes_Media; |
| 73 |
begin |
| 74 |
SIO.Create (png, SIO.Out_File, "bar_code_upca.png"); |
| 75 |
PNG_Bar_Code (Code_UPCA, 2, 100, "12345678901", SIO.Stream (png).all); |
| 76 |
SIO.Close (png); |
| 77 |
end Demo_UPCA; |
| 78 |
|
| 79 |
procedure Demo_EAN13 is |
| 80 |
use Bar_Codes, Bar_Codes_Media; |
| 81 |
begin |
| 82 |
SIO.Create (png, SIO.Out_File, "bar_code_ean13.png"); |
| 83 |
PNG_Bar_Code (Code_EAN13, 2, 100, "123456789012", SIO.Stream (png).all); |
| 84 |
SIO.Close (png); |
| 85 |
end Demo_EAN13; |
| 86 |
|
| 87 |
procedure Demo_QR is |
| 88 |
use Bar_Codes, Bar_Codes_Media; |
| 89 |
begin |
| 90 |
Create (svg, Out_File, "qr_code_l.svg"); |
| 91 |
SVG_Header; |
| 92 |
Put_Line (svg, SVG_Bar_Code (Code_QR_Low, 60.0, 60.0, "mm", hello_long)); |
| 93 |
Close (svg); |
| 94 |
-- |
| 95 |
Create (pdf, Out_File, "qr_code_q_pdf.txt"); |
| 96 |
Put_Line (pdf, PDF_Bar_Code (Code_QR_Quartile, (150.0, 120.0, 100.0, 100.0), hello_long)); |
| 97 |
Close (pdf); |
| 98 |
-- |
| 99 |
Create (pbm, Out_File, "qr_code_h.pbm"); |
| 100 |
Put_Line (pbm, PBM_Bar_Code (Code_QR_High, 5, 5, hello_long)); |
| 101 |
Close (pbm); |
| 102 |
-- |
| 103 |
SIO.Create (png, SIO.Out_File, "qr_code_h.png"); |
| 104 |
PNG_Bar_Code (Code_QR_High, 5, 5, hello_long, SIO.Stream (png).all); |
| 105 |
SIO.Close (png); |
| 106 |
end Demo_QR; |
| 107 |
|
| 108 |
procedure Demo_Data_Matrix is |
| 109 |
use Bar_Codes, Bar_Codes_Media; |
| 110 |
begin |
| 111 |
Create (svg, Out_File, "dm_code.svg"); |
| 112 |
SVG_Header; |
| 113 |
Put_Line (svg, SVG_Bar_Code (Code_DM_Square, 80.0, 80.0, "mm", hello_long)); |
| 114 |
Close (svg); |
| 115 |
-- |
| 116 |
Create (pbm, Out_File, "dm_code_rect.pbm"); |
| 117 |
Put_Line (pbm, PBM_Bar_Code (Code_DM_Rectangular, 10, 10, hello_short)); |
| 118 |
Close (pbm); |
| 119 |
-- |
| 120 |
SIO.Create (png, SIO.Out_File, "dm_code_rect.png"); |
| 121 |
PNG_Bar_Code (Code_DM_Rectangular, 10, 10, hello_short, SIO.Stream (png).all); |
| 122 |
SIO.Close (png); |
| 123 |
end Demo_Data_Matrix; |
| 124 |
|
| 125 |
begin |
| 126 |
Demo_Code_128; |
| 127 |
Demo_MSI; |
| 128 |
Demo_UPCA; |
| 129 |
Demo_EAN13; |
| 130 |
Demo_QR; |
| 131 |
Demo_Data_Matrix; |
| 132 |
end Bar_Codes_Demo; |