From bcb42bb431e26c5552452b21cbf657e712ffb736 Mon Sep 17 00:00:00 2001 From: Gianni Annunzio Date: Fri, 21 Feb 2020 17:02:50 +0100 Subject: [PATCH] Support array of streams for attribute contents in page object dictionary --- page.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/page.go b/page.go index 029393a..cb50d9b 100644 --- a/page.go +++ b/page.go @@ -404,9 +404,32 @@ type gstate struct { // Content returns the page's content. func (p Page) Content() Content { - strm := p.V.Key("Contents") - var enc TextEncoding = &nopEncoder{} + obj := p.V.Key("Contents") + + content := Content{} + if obj.Kind() == Stream { + content = interpretStream(p, obj) + } else if obj.Kind() == Array { + + for i := 0; i < obj.Len(); i++ { + val := obj.Index(i) + if val.Kind() == Stream { + part := interpretStream(p, val) + content.Text = append(content.Text, part.Text...) + content.Rect = append(content.Rect, part.Rect...) + } else { + panic("If the key contents contains an array then each item must be of type stream") + } + } + } else { + panic("The key content supports either a stream or an array (of streams) as a type") + } + return content +} + +func interpretStream(p Page, strm Value) Content { + var enc TextEncoding = &nopEncoder{} var g = gstate{ Th: 1, CTM: ident,