|
1 | 1 | use super::*; |
| 2 | +use crate::object::TextStrLike; |
2 | 3 | use crate::types::AnnotationType; |
3 | 4 |
|
4 | 5 | /// Writer for an _interactive forms dictionary_. PDF 1.2+. |
@@ -131,7 +132,7 @@ impl<'a> Field<'a> { |
131 | 132 | /// messages). This text is also useful when extracting the document's |
132 | 133 | /// contents in support of accessibility to users with disabilities or for |
133 | 134 | /// other purposes. PDF 1.3+. |
134 | | - pub fn alternate_name(&mut self, alternate: TextStr) -> &mut Self { |
| 135 | + pub fn alternate_name(&mut self, alternate: impl TextStrLike) -> &mut Self { |
135 | 136 | self.pair(Name(b"TU"), alternate); |
136 | 137 | self |
137 | 138 | } |
@@ -291,14 +292,14 @@ impl Field<'_> { |
291 | 292 |
|
292 | 293 | /// Write the `/V` attribute to set the value of this text field. |
293 | 294 | /// Only permissible on text fields. |
294 | | - pub fn text_value(&mut self, value: TextStr) -> &mut Self { |
| 295 | + pub fn text_value(&mut self, value: impl TextStrLike) -> &mut Self { |
295 | 296 | self.pair(Name(b"V"), value); |
296 | 297 | self |
297 | 298 | } |
298 | 299 |
|
299 | 300 | /// Start writing the `/DV` attribute to set the default value of this text |
300 | 301 | /// field. Only permissible on text fields. |
301 | | - pub fn text_default_value(&mut self, value: TextStr) -> &mut Self { |
| 302 | + pub fn text_default_value(&mut self, value: impl TextStrLike) -> &mut Self { |
302 | 303 | self.pair(Name(b"DV"), value); |
303 | 304 | self |
304 | 305 | } |
@@ -332,7 +333,11 @@ impl Field<'_> { |
332 | 333 |
|
333 | 334 | /// Write the `/RV` attribute to set the value of this variable text field. |
334 | 335 | /// Only permissible on fields containing variable text. PDF 1.5+. |
335 | | - pub fn vartext_rich_value(&mut self, value: TextStr) -> &mut Self { |
| 336 | + /// |
| 337 | + /// Note that this is a Rich Text string, so you can use some basic XHTML |
| 338 | + /// and XFA attributes. That also means that untrusted input must be |
| 339 | + /// properly escaped. |
| 340 | + pub fn vartext_rich_value(&mut self, value: impl TextStrLike) -> &mut Self { |
336 | 341 | self.pair(Name(b"RV"), value); |
337 | 342 | self |
338 | 343 | } |
@@ -443,30 +448,38 @@ writer!(ChoiceOptions: |obj| Self { array: obj.array() }); |
443 | 448 |
|
444 | 449 | impl ChoiceOptions<'_> { |
445 | 450 | /// Add an option with the given value. |
446 | | - pub fn option(&mut self, value: TextStr) -> &mut Self { |
| 451 | + pub fn option(&mut self, value: impl TextStrLike) -> &mut Self { |
447 | 452 | self.array.item(value); |
448 | 453 | self |
449 | 454 | } |
450 | 455 |
|
451 | 456 | /// Add options with the given values. |
452 | | - pub fn options<'b>( |
| 457 | + pub fn options( |
453 | 458 | &mut self, |
454 | | - values: impl IntoIterator<Item = TextStr<'b>>, |
| 459 | + values: impl IntoIterator<Item = impl TextStrLike>, |
455 | 460 | ) -> &mut Self { |
456 | 461 | self.array.items(values); |
457 | 462 | self |
458 | 463 | } |
459 | 464 |
|
460 | 465 | /// Add an option with the given value and export value. |
461 | | - pub fn export(&mut self, value: TextStr, export_value: TextStr) -> &mut Self { |
462 | | - self.array.push().array().items([export_value, value]); |
| 466 | + pub fn export( |
| 467 | + &mut self, |
| 468 | + value: impl TextStrLike, |
| 469 | + export_value: TextStr, |
| 470 | + ) -> &mut Self { |
| 471 | + { |
| 472 | + let mut array = self.array.push().array(); |
| 473 | + array.item(export_value); |
| 474 | + array.item(value); |
| 475 | + } |
463 | 476 | self |
464 | 477 | } |
465 | 478 |
|
466 | 479 | /// Add options with the given pairs of value and export value. |
467 | 480 | pub fn exports<'b>( |
468 | 481 | &mut self, |
469 | | - values: impl IntoIterator<Item = (TextStr<'b>, TextStr<'b>)>, |
| 482 | + values: impl IntoIterator<Item = (impl TextStrLike, TextStr<'b>)>, |
470 | 483 | ) -> &mut Self { |
471 | 484 | for (value, export) in values { |
472 | 485 | self.export(value, export); |
|
0 commit comments