| 1 |
% File: hawkdraw-patterns.code.tex |
| 2 |
% Copyright 2026 Jasper Habicht (mail(at)jasperhabicht.de). |
| 3 |
% |
| 4 |
% This work may be distributed and/or modified under the |
| 5 |
% conditions of the LaTeX Project Public License version 1.3c, |
| 6 |
% available at http://www.latex-project.org/lppl/. |
| 7 |
% |
| 8 |
% This file is part of the `hawkdraw' package (The Work in LPPL) |
| 9 |
% and all files in that bundle must be distributed together. |
| 10 |
% |
| 11 |
% This work has the LPPL maintenance status `maintained'. |
| 12 |
% |
| 13 |
% BOF |
| 14 |
|
| 15 |
% v0.0.7 2026-05-25 |
| 16 |
|
| 17 |
\msg_new:nnn { hawkdraw } { pattern-unknown } { |
| 18 |
Pattern ~ `#1` ~ unknown. |
| 19 |
} |
| 20 |
|
| 21 |
\prop_new:N \g_hawkdraw_pattern_default_keys_prop |
| 22 |
\clist_new:N \l_hawkdraw_pattern_keys_clist |
| 23 |
\box_new:N \l_hawkdraw_pattern_box |
| 24 |
|
| 25 |
\dim_new:N \l_hawkdraw_pattern_xunit_dim |
| 26 |
\dim_new:N \l_hawkdraw_pattern_yunit_dim |
| 27 |
|
| 28 |
\keys_define:nn { hawkdraw / path } { |
| 29 |
fill ~ pattern .code:n = { |
| 30 |
\tl_put_right:Nn \l_hawkdraw_path_postactions_tl { |
| 31 |
\draw_scope_begin: |
| 32 |
\bool_set_true:N \l__hawkdraw_path_clip_bool |
| 33 |
\tl_trim_spaces_apply:nN { \g_hawkdraw_path_current_tl} \__hawkdraw_process_path:e |
| 34 |
\draw_path_use_clear:n { clip } |
| 35 |
\hawkdraw_pattern_fill:nV {#1} \l_hawkdraw_pattern_keys_clist |
| 36 |
\bool_set_false:N \l__hawkdraw_path_clip_bool |
| 37 |
\bool_gset_false:N \g__hawkdraw_path_use_clip_bool |
| 38 |
\draw_scope_end: |
| 39 |
} |
| 40 |
} , |
| 41 |
pattern ~ style ~ set .clist_set:N = \l_hawkdraw_pattern_keys_clist , |
| 42 |
pattern ~ style ~ add .code:n = { |
| 43 |
\clist_put_right:Nn \l_hawkdraw_pattern_keys_clist {#1} |
| 44 |
} , |
| 45 |
pattern ~ x .dim_set:N = \l_hawkdraw_pattern_xunit_dim , |
| 46 |
pattern ~ x .initial:n = { 10pt } , |
| 47 |
pattern ~ y .dim_set:N = \l_hawkdraw_pattern_yunit_dim , |
| 48 |
pattern ~ y .initial:n = { 10pt } , |
| 49 |
} |
| 50 |
|
| 51 |
\cs_new_protected:Npn \hawkdraw_pattern_fill:nn #1#2 { |
| 52 |
\pdfxform_if_exist:nF { |
| 53 |
hawkdraw_pattern_ |
| 54 |
\str_mdfive_hash:n { #1 #2 } |
| 55 |
} { |
| 56 |
\hawkdraw_pattern_set:nn {#1} {#2} |
| 57 |
} |
| 58 |
\hbox_set:Nn \l_hawkdraw_pattern_box { |
| 59 |
\pdfxform_use:n { |
| 60 |
hawkdraw_pattern_ |
| 61 |
\str_mdfive_hash:n { #1 #2 } |
| 62 |
} |
| 63 |
} |
| 64 |
\tl_analysis_log:N \g_draw_bb_xmin_dim |
| 65 |
\tl_analysis_log:N \g_draw_bb_xmax_dim |
| 66 |
\tl_analysis_log:N \g_draw_bb_ymin_dim |
| 67 |
\tl_analysis_log:N \g_draw_bb_ymax_dim |
| 68 |
\bool_set_false:N \l_draw_bb_update_bool |
| 69 |
\int_step_inline:nnn { |
| 70 |
\fp_to_int:n { |
| 71 |
floor( \g_draw_bb_xmin_dim / \l_hawkdraw_pattern_xunit_dim ) |
| 72 |
} |
| 73 |
} { |
| 74 |
\fp_to_int:n { |
| 75 |
floor( \g_draw_bb_xmax_dim / \l_hawkdraw_pattern_xunit_dim ) |
| 76 |
} |
| 77 |
} { |
| 78 |
\int_step_inline:nnn { |
| 79 |
\fp_to_int:n { |
| 80 |
floor( \g_draw_bb_ymin_dim / \l_hawkdraw_pattern_yunit_dim ) |
| 81 |
} |
| 82 |
} { |
| 83 |
\fp_to_int:n { |
| 84 |
floor( \g_draw_bb_ymax_dim / \l_hawkdraw_pattern_yunit_dim ) |
| 85 |
} |
| 86 |
} { |
| 87 |
\draw_box_use:Nn \l_hawkdraw_pattern_box { |
| 88 |
##1 * \l_hawkdraw_pattern_xunit_dim |
| 89 |
, |
| 90 |
####1 * \l_hawkdraw_pattern_yunit_dim |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
\bool_set_true:N \l_draw_bb_update_bool |
| 95 |
} |
| 96 |
\cs_generate_variant:Nn \hawkdraw_pattern_fill:nn { nV } |
| 97 |
|
| 98 |
\cs_new_protected:Npn \hawkdraw_pattern_set:nn #1#2 { |
| 99 |
\pdfxform_new:nnn { hawkdraw_pattern_ \str_mdfive_hash:n { #1 #2 } } { } { |
| 100 |
\draw_suspend_begin: |
| 101 |
\draw_begin: |
| 102 |
\clist_clear:N \l_hawkdraw_path_use_clist |
| 103 |
\keys_set:ne { hawkdraw / path } { |
| 104 |
\prop_item:Nn \g_hawkdraw_pattern_default_keys_prop {#1} |
| 105 |
} |
| 106 |
\keys_set:nn { hawkdraw / path } {#2} |
| 107 |
\hawkdraw_set_path_options: |
| 108 |
\draw_path_rectangle:nn { 0pt , 0pt } { |
| 109 |
\l_hawkdraw_pattern_xunit_dim , \l_hawkdraw_pattern_yunit_dim |
| 110 |
} |
| 111 |
\draw_path_replace_bb: |
| 112 |
\bool_set_false:N \l_draw_bb_update_bool |
| 113 |
\use:c { hawkdraw_pattern_ #1 : } |
| 114 |
\draw_end: |
| 115 |
\draw_suspend_end: |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
\cs_new_protected:Npn \hawkdraw_pattern_create:nnn #1#2#3 { |
| 120 |
\prop_gput:Nnn \g_hawkdraw_pattern_default_keys_prop {#1} {#2} |
| 121 |
\cs_new_protected:cpn { hawkdraw_pattern_ #1 : } { |
| 122 |
#3 |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
% === |
| 127 |
|
| 128 |
\hawkdraw_pattern_create:nnn { lines } { } { |
| 129 |
\draw_path_moveto:n { 0pt , 5pt } |
| 130 |
\draw_path_lineto:n { 10pt , 5pt } |
| 131 |
\draw_path_use_clear:n { stroke } |
| 132 |
} |
| 133 |
|
| 134 |
\hawkdraw_pattern_create:nnn { hatch } { } { |
| 135 |
\draw_path_moveto:n { 0pt , 5pt } |
| 136 |
\draw_path_lineto:n { 10pt , 5pt } |
| 137 |
\draw_path_moveto:n { 5pt , 0pt } |
| 138 |
\draw_path_lineto:n { 5pt , 10pt } |
| 139 |
\draw_path_use_clear:n { stroke } |
| 140 |
} |
| 141 |
|
| 142 |
\hawkdraw_pattern_create:nnn { dots } { } { |
| 143 |
\draw_path_circle:nn { 5pt , 5pt } { 2.5pt} |
| 144 |
\draw_path_use_clear:n { fill } |
| 145 |
} |
| 146 |
|
| 147 |
%EOF |