• No results found

The l3pdffield-checkbox module Commands to create checkbox form fields L

N/A
N/A
Protected

Academic year: 2021

Share "The l3pdffield-checkbox module Commands to create checkbox form fields L"

Copied!
8
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

The l3pdffield-checkbox module

Commands to create checkbox form fields

L

A

TEX PDF management testphase bundle

The L

A

TEX Project

Version 0.95i, released 2021-08-28

1

l3pdffield-checkbox Introduction

This is the documentation for checkbox fields, for general information about form fields check the documentation l3pdffield.

Please keep in mind

• Not every PDF viewer supports checkboxes.

• The handling can depend on settings in the PDF viewer. In adobe reader for example I had to disable an option to avoid that it tries to create an appearance itself

• Standards like pdf/A disable features of form fields too (as you typically can’t change the PDF).

2

Checkboxes

Click me:

2.1

Commands

\pdffield_checkbox:n{⟨key val list ⟩}

This creates a checkbox to check and uncheck. The list of allowed keys is described below. The ⟨key val list⟩ should at least set the name, without it the default name checkbox is used. Checkboxes with the same name belong to the same field and are checked and unchecked together. The default appearance is a quadratic frame with a \texttimes in it for the checked case. The default appearance is setup at the first use and will use the font family active at that time.

(2)

2.2

Keys

The new checkbox command accept all field and annot keys from l3pdffield. A few keys are disabled or are forced to specific values. The appearance keys have a more check-box specific behaviour, other keys have other defaults than with the basic commands. Additionally there are a small number of keys specific to a checkbox. For convenience a number of important keys are documented here too, even if they are already in the document from l3pdffield.

Disabled keys are

• V, DV, AS: use checked instead. • FT is overwritten.

• For checkboxes only the field flags ReadOnly, Required and NoExport make sense. Radio, Pushbotton are set automatically automatically by the code as this is re-quired for a checkbox.

preset-checkbox = {⟨key-val-list ⟩}

This allows to set default keys for a checkbox.

preset-checkbox

name = ⟨partial name ⟩ T = ⟨partial name ⟩

This sets the partial name of the field. The value shouldn’t contain a period, be not empty and sensibly consist of simple chars. Additionally the value is used to create the field ID. This means that checkboxes with the same partial name are annotations with the same field as parent and are checked and unchecked together—this what is typically expected. The field ID is then internal and can not be used to attach another annotation. For explicit control of the field ID use the fieldID key.

name T

fieldID = ⟨field ID ⟩

For experts only! This allows to give the checkbox field a specific ID. This is only useful in the context of a larger fieldset, if for example you want to use the same partial name for more than one field, or if you want to attach another annotation to the field with \pdffield_annot:n. If used wrongly you can easily create invalid fieldset. It allows you to create to fields with the same partial name, but if you want to see both you need to ensure that their full names are different—for example by adding some parent fields.

fieldID

parent = ⟨field ID ⟩

This is only needed if the field should be part of a larger fieldset. The value should be a field ID of a field created previously with \pdffield_field:nn.

parent

altname = ⟨string ⟩ TU = ⟨string ⟩

This is sets an alternative name for user interaction. This name can only be set at the first checkbox instance, when the field is initialized.

(3)

mappingname = ⟨string ⟩ TM = ⟨string ⟩

This is sets an alternative name for export. This name can only be set at the first checkbox instance, when the field is initialized.

mappingname TM

width = ⟨dim expression ⟩ height = ⟨dim expression ⟩ depth = ⟨dim expression ⟩

These keys allow to set the dimensions of checkbox instance. The value should be a dimension expression. By default width and height use \normalbaselineskip, the depth is zero.

width height depth

AP/N = ⟨partial appearance name ⟩ appearance = ⟨partial appearance name ⟩ AP/R = ⟨partial appearance name ⟩

rollover-appearance = ⟨partial appearance name ⟩ AP/D = ⟨partial appearance name ⟩

down-appearance = ⟨partial appearance name ⟩

This keys sets the normal appearance, the rollover appearance (when the mouse hovers over the checkbox) and the down appearance (when the mouse clicks). They take as value a ⟨partial appearance name⟩ and expects that two form Xobjects ⟨partial appearance name⟩/Yes and ⟨partial appearance name⟩/Off has been created. The initial value is pdffield/checkbox/default for the normal appearance and shows a \texttimes. The other appearances are not set by default.

AP/N appearance AP/R rollover-appearance AP/D down-appearance checked = true|false

This is a boolean key which allows to set if the checkbox should be initially checked or not. It sets the /V and /DV key of the field and the /AS key of the annotation instance. It is possible to use different values for different instances, if one wants to confuse the user.

checked

value = Yes|Off default = Yes|Off

With checkboxes this two key are simply an alternative input for checked.

value default

2.3

Using with hyperref

The \CheckBox command from hyperref also prints a label, something that the command here doesn’t do. A redefinition like the following should allow \CheckBox to use the commands of this module. Be aware that the behaviour will not be identical! Not every setting and key from hyperref has been copied.

\ExplSyntaxOn\makeatletter

(4)

2.4

Some background

For some general background about fieldsets, fields and field annotations, please check l3pdffield. Here are only some remarks about the special case of checkboxes.

A checkbox consist of a field along with one or more field annotations. The annota-tions can appear on more than one page or locaannota-tions and if one instance is checked all other instances follows and are checked too.

A checkbox has two different looks: checked and unchecked. The hyperref imple-mentation uses symbolic names for the two states and adds some values with the /MK key and lets the PDF viewer create a look from them. But this doesn’t work reliably and is one of the reasons why a reimplementation is needed. Also newer PDF versions deprecate the /NeedAppearances setting and require that such a look, an “appearance”, is given as form XObjects. So the code forces the use of two appearances.

3

l3pdffield-checkbox Implementation

1 ⟨*package⟩ 2 ⟨@@=pdffield⟩

3.1

Variables

There are no specific variables.

3.2

Messages

There are no specific messages.

3.3

Appearances

The default appearances are a quadratic frame with cross (\texttimes) if checked. User appearances should have two versions and follow the naming module/⟨name⟩/Yes and module/⟨name⟩/Off.

\__pdffield_checkbox_default_appearances: pdffield/checkbox/default/Yes pdffield/checkbox/default/Off

This defines the standard appearance. It is setup at the first use of a checkbox, and will adapt to the font family in use then.

(5)

20 }

21 \cs_gset_eq:NN \__pdffield_checkbox_default_appearances: \prg_do_nothing: 22 }

(End definition for \__pdffield_checkbox_default_appearances: , pdffield/checkbox/default/Yes , and pdffield/checkbox/default/Off. These functions are documented on page ??.)

3.4

Creating the field

A field should be created if the name doesn’t exist

\__pdffield_checkbox_field:n

23 \cs_new_protected:Npn \__pdffield_checkbox_field:n #1 %name 24 { 25 \pdf_object_if_exist:nF {__pdffield/field/__pdffield/checkbox/#1} 26 { 27 \__pdffield_field:n { __pdffield/checkbox/#1 } 28 } 29 \keys_set:nn {pdffield}{parent=__pdffield/checkbox/#1} 30 } 31 \cs_generate_variant:Nn \__pdffield_checkbox_field:n {V}

(End definition for \__pdffield_checkbox_field:n.)

3.5

Assembling the checkbox

\__pdffield_checkbox:n 32 \cs_new_protected:Npn \__pdffield_checkbox:n #1 33 { 34 \group_begin: 35 \__pdffield_checkbox_default_appearances: 36 \cs_set_eq:NN\__pdffield_appearance_handler:nnn \__pdffield_checkbox_appearance_handler:nnn 37 \cs_set_eq:NN\__pdffield_value_handler:n \__pdffield_checkbox_value_handler:n 38 \cs_set_eq:NN\__pdffield_default_handler:n \__pdffield_checkbox_default_handler:n

Setting up the defaults.

39 \keys_set:nn {pdffield} 40 { 41 fieldID=, 42 name=checkbox, 43 appearance = pdffield/checkbox/default, 44 checked=false, 45 width = \normalbaselineskip, 46 height = \normalbaselineskip, 47 }

Value keys should be undefined.

48 \__pdffield_key_disable:nnn{checkbox}{V}{checked} 49 \__pdffield_key_disable:nnn{checkbox}{DV}{checked} 50 \__pdffield_key_disable:nnn{checkbox}{AS}{checked} 51 \keys_set:nn { pdffield }{__pdffield/preset/checkbox,#1} 52 \keys_set:nn { pdffield }

53 {

(6)

56 }

57 \tl_if_empty:NT\l__pdffield_fieldID_tl 58 {

59 \pdfdict_get:nnN {l__pdffield/field}{T}\l__pdffield_fieldID_tl 60 \tl_put_left:Nn \l__pdffield_fieldID_tl {__pdffield/checkbox/} 61 }

62 \__pdffield_checkbox_field:V\l__pdffield_fieldID_tl 63 \__pdffield_annot:

64 \group_end: 65 }

(End definition for \__pdffield_checkbox:n.)

3.6

Keys

Most keys are inherited simply the ones from the generic field and annot keys. A key to decide if the box is initially checked or not. We stay in the same family so that we can build a style.

checked This is a key specific for checkbox, it sets both field and annotation keys.

66 \keys_define:nn { pdffield } 67 {

68 ,checked .choice:

69 ,checked / false .code:n = 70 {

71 \pdfdict_put:nnx { l__pdffield/field }{V} { /Off } 72 \pdfdict_put:nnx { l__pdffield/field }{DV}{ /Off } 73 \pdfannot_dict_put:nnn {widget}{AS}{ /Off } 74 }

75 ,checked / true .code:n = 76 {

77 \pdfdict_put:nnx { l__pdffield/field }{V} { /Yes }

78 \pdfdict_put:nnx { l__pdffield/field }{DV}{ /Yes } 79 \pdfannot_dict_put:nnn {widget}{AS}{ /Yes } 80 }

81 ,checked .default:n = {true} 82 ,checked .groups:n = {checkbox} 83 }

84 \keys_define:nn { pdffield } 85 {

86 ,__value .choice:

87 ,__value / Off .code:n = 88 {

89 \pdfdict_put:nnx { l__pdffield/field }{V} { /Off } 90 \pdfdict_put:nnx { l__pdffield/field }{DV}{ /Off } 91 \pdfannot_dict_put:nnn {widget}{AS}{ /Off } 92 }

93 ,__value / Yes .code:n =

94 {

(7)

(End definition for checked. This function is documented on page3.)

\__pdffield_checkbox_value_handler:n \__pdffield_checkbox_default_handler:n

value and default do the same as checked.

100 \cs_new_protected:Npn \__pdffield_checkbox_value_handler:n #1 101 { 102 \keys_set:nn{pdffield}{__value={#1}} 103 } 104 \cs_new_protected:Npn \__pdffield_checkbox_default_handler:n #1 105 { 106 \keys_set:nn{pdffield}{__value={#1}} 107 }

(End definition for \__pdffield_checkbox_value_handler:n and \__pdffield_checkbox_default_-handler:n.)

\__pdffield_checkbox_appearance_handler:nnn Appearances must create a dictionary, so we define a special handler. {⟨name⟩} is the xform name without the /Yes, /Off, {⟨type⟩} is N, R, or D, {⟨text⟩} is a word for the error message.

108 \cs_new_protected:Npn \__pdffield_checkbox_appearance_handler:nnn #1 #2 #3 %name, type, text 109 { 110 \pdfxform_if_exist:nTF { #1/Yes } 111 { 112 \pdf_object_if_exist:nF {__pdffield/checkbox/AP/#1} 113 { 114 \pdf_object_new:nn {__pdffield/checkbox/AP/#1}{dict} 115 \pdf_object_write:nx 116 {__pdffield/checkbox/AP/#1} 117 {

118 /Yes ~ \pdfxform_ref:n { #1/Yes} 119 /Off ~ \pdfxform_ref:n { #1/Off}

120 } 121 } 122 \pdfannot_dict_put:nnx {widget/AP}{#2}{\pdf_object_ref:n{__pdffield/checkbox/AP/#1}} 123 } 124 { 125 \msg_error:nnnn{pdffield}{appearance-missing}{#1}{#3} 126 } 127 } 128

(End definition for \__pdffield_checkbox_appearance_handler:nnn.)

3.7

user commands

\pdffield_checkbox:n

129 \cs_set_eq:NN \pdffield_checkbox:n \__pdffield_checkbox:n 130 ⟨/package⟩

(8)

Index

The italic numbers denote the pages where the corresponding entry is described, numbers underlined point to the definition, all others indicate the places where it is used.

A altname . . . 2 AP/D . . . 3 AP/N . . . 3 AP/R . . . 3 appearance . . . 3 C \CheckBox . . . 3 checked . . . 3,66 D default . . . 3 depth . . . 3 down-appearance . . . 3 F fieldID . . . 2 \framebox . . . 9,17 H height . . . 3 M mappingname . . . 3 N name . . . 2 \normalbaselineskip . . . 3,45,46 P parent . . . 2 pdf commands: \pdf_object_write:nn . . . 115 pdfannot commands: \pdfannot_dict_put:nnn . . . 122 pdfdict commands: \pdfdict_put:nnn . . . . . . . 71,72,77,78,89,90,95,96 pdffield commands: \pdffield_annot:n . . . 2 \pdffield_appearance:nn . . . 5,13 \pdffield_checkbox:n . . . . 1,129,129 \pdffield_field:nn . . . 2

Referenties

GERELATEERDE DOCUMENTEN

We assume that for all ionic species in- volved in surface charge generation (Ca 2+, OH-, silicate) there are different types of adsorption sites, OH-

Bij aanleg van de eerste profielput werd al snel duidelijk dat behalve de kaaimuur het hele plangebied verstoord is door de aanleg van nutsleidingen uit de nieuwste tijd

Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of

Voor de niet-rechthoekige zaal re- sulteren de zorgvuldig gekozen vorm en absorptie en dif- fusiecoefficienten (= fractie van de geluidenergie die diffuus wordt

A reset action can be defined and used like this \pdffield_reset_new:nn {myreset} { fields= {A,B,C}, exclude % or include }

Most keys are inherited simply the ones from the generic field and annot keys. We define a group key, as the name is better. The value key sets the export value. default the

The new pushbutton command accept all field and annot keys from l3pdffield!. A few keys are disabled or are forced to

Most keys are inherited simply the ones from the generic field and annot keys. We define a group key, as the name is better. The value key sets the export value. default the