Skip to content

Commit

Permalink
Add some locks for concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Aug 19, 2024
1 parent f6ddf0c commit 96adf7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
29 changes: 1 addition & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ PDF::API6 - A Raku PDF API
- [NAME](#name)
- [DESCRIPTION](#description)
- [EXAMPLE](#example)
- [DIFFERENCES BETWEEN PDF::API2 AND PDF::API6](#differences-between-pdfapi2-and-pdfapi6)
- [PDF::API6](#pdfapi6)
- [TODO](#todo)
- [SYNOPSIS](#synopsis)
- [SECTION I: Input/Output Methods (inherited from PDF)](#section-i-inputoutput-methods-inherited-from-pdf)
- [Input/Output](#inputoutput)
Expand Down Expand Up @@ -141,30 +138,6 @@ $pdf.save-as: "tmp/hello-world.pdf";

![example.pdf](https://raw.githubusercontent.com/pdf-raku/PDF-API6/master/tmp/.previews/hello-world-001.png)

# DIFFERENCES BETWEEN PDF::API2 AND PDF::API6

## PDF::API6

- Has a Graphics State engine. This is based on the graphics operators and variables as described PDF 32000 chapter 8 "Graphics and the operators".

- Supports the creation and manipulation of XObject Forms and Patterns.

- Implements an Object Graph model for data access. A PDF file is modelled as an object tree of Dictionaries (Hashes) and Arrays that contain simpler
values such as Integers, Reals and Strings.

## TODO

PDF::API2 features that are not yet available in PDF::API6 include:

- Images. PDF::API6 supports PNG, JPEG and GIF images

- currently not supported are: TIFF and PNM images.

- Fonts

- Synthetic fonts are NYI (wanted: module PDF::Font::Synthetic)


# SYNOPSIS

```raku
Expand Down Expand Up @@ -1595,7 +1568,7 @@ links that are both internally and externally accessible.
PDF::API6 has some basic ability to tag graphical content.
See also the [PDF::Tags](https://pdf-raku.github.io/PDF-Tags-raku/) module,
which can be used with PDF::API and provides more functionality.
which can be used with this module and provides more functionality.
### tag
Expand Down
17 changes: 10 additions & 7 deletions lib/PDF/API6.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PDF::API6:ver<0.2.8>
use PDF::COS::Name;
use PDF::API6::Preferences;
use PDF::Content::Text::Box;
has Lock $!lock handles<protect> .= new() ;

subset PageRef where {$_ ~~ UInt|Str|PDF::Page|PDF::Destination|PDF::Action::GoTo};
sub prefix:</>($name) { PDF::COS::Name.COERCE($name) };
Expand Down Expand Up @@ -66,7 +67,7 @@ class PDF::API6:ver<0.2.8>

has PDF::API6::Preferences $.preferences;
method preferences {
$!preferences //= PDF::API6::Preferences.new: :$.catalog;
$.protect: { $!preferences //= PDF::API6::Preferences.new: :$.catalog };
}

#| Make a miscellaneous named destination
Expand Down Expand Up @@ -137,17 +138,19 @@ class PDF::API6:ver<0.2.8>
}
multi method action( PDF::Action::URI :$uri!) { $uri; }

method outlines is rw { self.catalog.Outlines //= {} };
method outlines is rw { $.protect: { self.catalog.Outlines //= %() } };

method is-encrypted { ? self.Encrypt }
method info returns PDF::Info { self.Info //= {} }

has PDF::Metadata::XML $.xmp-metadata is rw;
method xmp-metadata is rw {
$!xmp-metadata //= ($.catalog.Metadata //= {
:Type(/<Metadata>),
:Subtype(/<XML>),
});
$.protect: {
$!xmp-metadata //= ($.catalog.Metadata //= {
:Type(/<Metadata>),
:Subtype(/<XML>),
});
}

$!xmp-metadata.decoded; # rw target
}
Expand Down Expand Up @@ -235,7 +238,7 @@ class PDF::API6:ver<0.2.8>
# final finishing hook for document. Called just prior to serializing
if %!attachments {
# new attachments to be added
my $names = $.catalog.Names //= {};
my $names = $.protect: { $.catalog.Names //= %() };
with $names.EmbeddedFiles {
# construct a simple name tree /EmbeddedFiles entry in the Catalog. If
# there's an existing tree, just flatten it. Potentially expensive for
Expand Down

0 comments on commit 96adf7a

Please sign in to comment.