if matrix is None: # Compatibility with older note format matrix = np.eye(3,3) else: matrix = np.asarray(json.loads(matrix)["values"], dtype=np.float32).reshape(3,3) d = np.frombuffer(points, dtype=np.float32) d = d.byteswap() d = d.reshape(-1, 6) pressure = (d[:,2] / pressure_norm) ** pressure_pow # Projection matrix points = d[:, :2] points = np.concatenate((points, np.ones([points.shape[0],1])), axis=1) points = points @ matrix.T points = points[:, :2] #### #!/usr/bin/env perl use v5.38; use strict; use warnings; use DBI; use DBD::SQLite; use Data::Dumper; use JSON::XS; use Carp; my $basedir = 'Testfiles'; if(!defined($ARGV[0])) { croak("No note name given!"); } #my ($WIDTH, $HEIGHT) = (XXXXXXX my $notename = $ARGV[0]; my ($noteuid, $pages) = getUID($basedir, $notename); print "Note has UID ", $noteuid, " with ", scalar @{$pages}, " pages: ", join(', ', @{$pages}), "\n"; my $pagecount = 0; foreach my $page (@{$pages}) { my $pagefname = '' . $notename . '_page' . $pagecount . '.png'; $pagefname =~ s/\ /_/g; renderPage($basedir, $noteuid, $page, $pagefname); } sub renderPage($basedir, $noteuid, $page, $pagefname) { print "******* $pagefname *******\n"; my $fname = $basedir . '/' . $noteuid . '.db'; if(!-f $fname) { croak("File $fname not found!"); } my $dbh = DBI->connect("dbi:SQLite:dbname=$fname","","") or croak($!); my $selsth = $dbh->prepare("SELECT * FROM NewShapeModel WHERE documentUniqueId = ? AND pageUniqueId = ? ORDER BY id") or croak($dbh->errstr); if(!$selsth->execute($noteuid, $page)) { print $dbh->errstr, "\n"; $dbh->disconnect; croak("DB Error"); } my @lines; while((my $line = $selsth->fetchrow_hashref)) { # de-JSON certain fields foreach my $key (qw[boundingRect matrixValues shapeLineStyle shapeCreateArgs]) { if(!defined($line->{$key}) || $line->{$key} eq '') { $line->{$key} = {}; } else { my $tmp = decode_json $line->{$key}; $line->{$key} = $tmp; } push @lines, $line; } } #$img = GD::Image->new($self->{width}, $self->{height}); #$imgblack = $self->{img}->colorAllocate(0, 0, 0); #$imgwhite = $self->{img}->colorAllocate(255, 255, 255); return; } sub getUID($basedir, $name) { my $fname = $basedir . '/ShapeDatabase.db'; if(!-f $fname) { croak($fname . " not found"); } my $dbh = DBI->connect("dbi:SQLite:dbname=$fname","","") or croak($!); my $selsth = $dbh->prepare("SELECT * FROM NoteModel WHERE title = ?") or croak($dbh->errstr); if(!$selsth->execute($name)) { print $dbh->errstr, "\n"; $dbh->disconnect; croak("DB Error"); } my $line = $selsth->fetchrow_hashref; $selsth->finish; $dbh->disconnect; #print Dumper($line); if(defined($line) && defined($line->{uniqueId})) { my $pages = []; if(defined($line->{pageNameList})) { my $json = $line->{pageNameList}; #print "JSON: $json\n"; my $decoded = decode_json $json; #print "Decoded: ", Dumper($decoded); if(!defined($decoded->{pageNameList})) { print "BLI\n"; } else { print "BLA\n"; $pages = $decoded->{pageNameList}; } } print Dumper($pages); return ($line->{uniqueId}, $pages); } croak("Note not found in ". $fname); }