@@ -140,17 +140,13 @@ static std::string fmt(const Object &o, const UnicodeMap *uMap) {
140140 auto s = o.getString ();
141141
142142 char buf[9 ];
143- Unicode *ucs4_out;
144143 std::vector<Unicode> ucs4 = TextStringToUCS4 (s->toStr ());
145- ucs4_out = (Unicode *)gmallocn (ucs4.size (), sizeof (Unicode));
146- memcpy (ucs4_out, ucs4.data (), ucs4.size () * sizeof (Unicode));
147- auto len = ucs4.size ();
148144
149145 std::string out;
150- out.reserve (static_cast < size_t >(len ));
146+ out.reserve (ucs4. size ( ));
151147
152- for (unsigned long int i = 0 ; i < len; i++ ) {
153- auto n = uMap->mapUnicode (ucs4_out[i] , buf, sizeof (buf));
148+ for (const auto &uChar : ucs4 ) {
149+ auto n = uMap->mapUnicode (uChar , buf, sizeof (buf));
154150 out.append (buf, n);
155151 }
156152
@@ -199,7 +195,7 @@ void dump_font_info(PDFDoc *doc) {
199195void pack_stream_content (Stream *stream) {
200196 GooString content;
201197
202- stream->reset ();
198+ stream->rewind ();
203199 stream->fillGooString (&content);
204200 stream->close ();
205201
@@ -307,8 +303,6 @@ void dump_document_meta(const std::string filename, PDFDoc *doc,
307303 }
308304}
309305
310- void TextPageDecRef (TextPage *text_page) { text_page->decRefCnt (); }
311-
312306void render_annotations (std::unique_ptr<Gfx> &gfx, Annots *annots) {
313307 gfx->saveState ();
314308
@@ -319,7 +313,7 @@ void render_annotations(std::unique_ptr<Gfx> &gfx, Annots *annots) {
319313 gfx->restoreState ();
320314}
321315
322- typedef std::unique_ptr<TextPage, decltype (&TextPageDecRef) > TextPagePtr;
316+ typedef std::unique_ptr<TextPage> TextPagePtr;
323317
324318TextPagePtr page_to_text_page (Page *page) {
325319 auto dev = std::make_unique<TextOutputDev>(nullptr , true , 0 , false , false );
@@ -343,7 +337,7 @@ TextPagePtr page_to_text_page(Page *page) {
343337
344338 dev->endPage ();
345339
346- return TextPagePtr ( dev->takeText (), TextPageDecRef );
340+ return dev->takeText ();
347341}
348342
349343int count_glyphs (const std::vector<std::vector<std::unique_ptr<TextWordSelection>>>& word_list) {
@@ -439,7 +433,7 @@ void dump_page_bitmap(Page *page) {
439433 // auto mode = splashModeRGB8;
440434 // const auto n_channels = 3;
441435
442- auto dev = std::make_unique<SplashOutputDev>(mode, 4 , false , paperColor,
436+ auto dev = std::make_unique<SplashOutputDev>(mode, 4 , paperColor,
443437 true , splashThinLineShape);
444438
445439 dev->setFontAntialias (true );
@@ -502,14 +496,14 @@ void dump_document(PDFDoc *doc, const Options &options) {
502496 }
503497}
504498
505- BaseStream * open_file (const std::string filename) {
499+ std::unique_ptr< BaseStream> open_file (const std::string filename) {
506500 std::unique_ptr<GooFile> file = GooFile::open (filename);
507501 if (file == NULL ) {
508502 std::cerr << " Failed to open " << filename << std::endl;
509503 exit (5 );
510504 }
511- Object obj ;
512- return new FileStream (file.release (), 0 , false , file-> size () , Object::null ());
505+ auto size = file-> size () ;
506+ return std::make_unique< FileStream> (file.release (), 0 , false , size, Object::null ());
513507}
514508
515509std::string parse_page_range (std::string value, Options *options) {
@@ -618,7 +612,7 @@ int main(int argc, char *argv[]) {
618612 exit (127 );
619613 }
620614
621- std::unique_ptr<PDFDoc> doc (new PDFDoc (file));
615+ std::unique_ptr<PDFDoc> doc (new PDFDoc (std::move ( file) ));
622616 if (!doc) {
623617 std::cerr << " Problem loading document." << std::endl;
624618 exit (64 );
0 commit comments