Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/img/badges.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions fpdf/attachments.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !wasm

// Copyright ©2023 The go-pdf Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
Expand Down
43 changes: 43 additions & 0 deletions fpdf/attachments_wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//go:build wasm

package fpdf

import (
. "github.com/tinywasm/fmt"
)

type Attachment struct {
Content []byte
Filename string
Description string
objectNumber int
}

type annotationAttach struct {
*Attachment
x, y, w, h float64
}

func (f *Fpdf) SetAttachments(as []Attachment) {
f.err = Err("attachments", "unsupported", "in WASM")
}

func (f *Fpdf) AddAttachmentAnnotation(a *Attachment, x, y, w, h float64) {
f.err = Err("attachments", "unsupported", "in WASM")
}

func (f *Fpdf) putAttachments() {
// no-op in WASM
}

func (f *Fpdf) putAnnotationsAttachments() {
// no-op in WASM
}

func (f *Fpdf) getEmbeddedFiles() string {
return ""
}

func (f *Fpdf) putAttachmentAnnotationLinks(out *fmtBuffer, page int) {
// no-op in WASM
}
2 changes: 1 addition & 1 deletion fpdf/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ func (f *fontDefType) Schema() []fmt.Field {
{Name: "Desc", Type: fmt.FieldStruct},
{Name: "Up", Type: fmt.FieldInt},
{Name: "Ut", Type: fmt.FieldInt},
{Name: "Cw", Type: fmt.FieldInt},
{Name: "Cw", Type: fmt.FieldIntSlice},
{Name: "Enc", Type: fmt.FieldText},
{Name: "Diff", Type: fmt.FieldText},
{Name: "File", Type: fmt.FieldText},
Expand Down
4 changes: 2 additions & 2 deletions fpdf/exampleDir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func NewDocPdfTest(options ...any) *fpdf.Fpdf {
pdf := fpdf.New(options...)
pdf.SetCompression(false)
pdf.SetCatalogSort(true)
pdf.SetCreationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
pdf.SetModificationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
pdf.SetCreationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC).UnixNano())
pdf.SetModificationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC).UnixNano())

return pdf
}
Expand Down
24 changes: 24 additions & 0 deletions fpdf/font.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !wasm

package fpdf

import (
Expand All @@ -12,6 +14,28 @@ import (
. "github.com/tinywasm/fmt"
)

// fileExist returns true if the specified normal file exists
func fileExist(filename string) (ok bool) {
info, err := os.Stat(filename)
if err == nil {
if ^os.ModePerm&info.Mode() == 0 {
ok = true
}
}
return ok
}

// fileSize returns the size of the specified file; ok will be false
// if the file does not exist or is not an ordinary file
func fileSize(filename string) (size int64, ok bool) {
info, err := os.Stat(filename)
ok = err == nil
if ok {
size = info.Size()
}
return
}

func baseNoExt(fileStr string) string {
str := filepath.Base(fileStr)
extLen := len(filepath.Ext(str))
Expand Down
13 changes: 7 additions & 6 deletions fpdf/fontid_wasm.go → fpdf/fontid.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//go:build wasm

package fpdf

import (
. "github.com/tinywasm/fmt"
"github.com/tinywasm/unixid"
)

var uid, _ = unixid.NewUnixID()

func generateImageID(info *ImageInfoType) (string, error) {
// Simple deterministic ID for WASM to avoid crypto/sha1
return Sprintf("img_%d_%d_%d", int(info.w), int(info.h), len(info.data)), nil
var id string
uid.SetNewID(&id)
return id, nil
}

// generateFontID generates a font Id from the font definition
func generateFontID(fdt fontDefType) (string, error) {
// Simple deterministic ID for WASM
// Simple deterministic ID
return fdt.Tp + "_" + fdt.Name, nil
}
40 changes: 0 additions & 40 deletions fpdf/fontid_back.go

This file was deleted.

2 changes: 0 additions & 2 deletions fpdf/fonts_json_wasm.go → fpdf/fonts_json.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build wasm

package fpdf

import (
Expand Down
11 changes: 0 additions & 11 deletions fpdf/fonts_json_back.go

This file was deleted.

6 changes: 3 additions & 3 deletions fpdf/fpdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ func Test_SVGBasicWrite(t *testing.T) {
`web control is supported and is used in this example.`
html := pdf.HTMLBasicNew()
html.Write(lineHt, htmlStr)
sig, err = fpdf.SVGBasicFileParse(ImageFile(sigFileStr))
sig, err = pdf.SVGBasicFileParse(ImageFile(sigFileStr))
if err == nil {
scale := 100 / sig.Wd
scaleY := 30 / sig.Ht
Expand Down Expand Up @@ -1345,7 +1345,7 @@ func Test_SVGBasicDraw(t *testing.T) {
`size is used. scale 1.0 is pt`
html := pdf.HTMLBasicNew()
html.Write(lineHt, htmlStr)
sig, err = fpdf.SVGBasicFileParse(ImageFile(sigFileStr))
sig, err = pdf.SVGBasicFileParse(ImageFile(sigFileStr))
if err == nil {
pdf.SetLineCapStyle("round")
pdf.SetLineWidth(0.15)
Expand Down Expand Up @@ -2696,7 +2696,7 @@ func Test_SetModificationDate(t *testing.T) {
// ModDate: Sun Jan 2 10:22:30 2000
pdf := NewDocPdfTest()
pdf.AddPage()
pdf.SetModificationDate(time.Date(2000, 1, 2, 10, 22, 30, 0, time.UTC))
pdf.SetModificationDate(time.Date(2000, 1, 2, 10, 22, 30, 0, time.UTC).UnixNano())
fileStr := Filename("Test_SetModificationDate")
err := pdf.OutputFileAndClose(fileStr)
SummaryCompare(err, fileStr)
Expand Down
10 changes: 6 additions & 4 deletions fpdf/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ func TestGetConversionRatio(t *testing.T) {
}

func TestGetCreationDate(t *testing.T) {
setDate, _ := time.Parse(time.RFC3339, "2003-06-17T01:23:45Z")
tm, _ := time.Parse(time.RFC3339, "2003-06-17T01:23:45Z")
setDate := tm.UnixNano()
pdf := NewDocPdfTest()
pdf.SetCreationDate(setDate)

creationDate := pdf.GetCreationDate()

if got, want := creationDate, setDate; !got.Equal(want) {
if got, want := creationDate, setDate; got != want {
t.Errorf("invalid creationDate: got=%v, want=%v", got, want)
}
}
Expand Down Expand Up @@ -446,13 +447,14 @@ func TestGetMargins(t *testing.T) {
}

func TestGetModificationDate(t *testing.T) {
setDate, _ := time.Parse(time.RFC3339, "9-08-02T09:54:32Z")
tm, _ := time.Parse(time.RFC3339, "2009-08-02T09:54:32Z")
setDate := tm.UnixNano()
pdf := NewDocPdfTest()
pdf.SetModificationDate(setDate)

modificationDate := pdf.GetModificationDate()

if got, want := modificationDate, setDate; !got.Equal(want) {
if got, want := modificationDate, setDate; got != want {
t.Errorf("invalid modificationDate: got=%v, want=%v", got, want)
}
}
Expand Down
2 changes: 2 additions & 0 deletions fpdf/list/list.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !wasm

package main

import (
Expand Down
5 changes: 2 additions & 3 deletions fpdf/svgbasic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fpdf

import (
"encoding/xml"
"os"

. "github.com/tinywasm/fmt"
)
Expand Down Expand Up @@ -297,9 +296,9 @@ func SVGBasicParse(buf []byte) (sig SVGBasicType, err error) {

// SVGBasicFileParse parses a simple scalable vector graphics (SVG) file into a
// basic descriptor. The SVGBasicWrite() example demonstrates this method.
func SVGBasicFileParse(svgFileStr string) (sig SVGBasicType, err error) {
func (f *Fpdf) SVGBasicFileParse(svgFileStr string) (sig SVGBasicType, err error) {
var buf []byte
buf, err = os.ReadFile(svgFileStr)
buf, err = f.readFile(svgFileStr)
if err == nil {
sig, err = SVGBasicParse(buf)
}
Expand Down
2 changes: 0 additions & 2 deletions fpdf/time_wasm.go → fpdf/time.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build wasm

package fpdf

import (
Expand Down
57 changes: 0 additions & 57 deletions fpdf/time_back.go

This file was deleted.

2 changes: 0 additions & 2 deletions fpdf/types_wasm.go → fpdf/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build wasm

package fpdf

type pdfTime int64
7 changes: 0 additions & 7 deletions fpdf/types_back.go

This file was deleted.

22 changes: 0 additions & 22 deletions fpdf/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"io"
"math"
"os"

. "github.com/tinywasm/fmt"
)
Expand Down Expand Up @@ -33,27 +32,6 @@ func sprintf(fmtStr string, args ...any) string {
return Sprintf(fmtStr, args...)
}

// fileExist returns true if the specified normal file exists
func fileExist(filename string) (ok bool) {
info, err := os.Stat(filename)
if err == nil {
if ^os.ModePerm&info.Mode() == 0 {
ok = true
}
}
return ok
}

// fileSize returns the size of the specified file; ok will be false
// if the file does not exist or is not an ordinary file
func fileSize(filename string) (size int64, ok bool) {
info, err := os.Stat(filename)
ok = err == nil
if ok {
size = info.Size()
}
return
}

// utf8toutf16 converts UTF-8 to UTF-16BE; from http://www.fpdf.org/
func utf8toutf16(s string, withBOM ...bool) string {
Expand Down
Loading