MCPcopy Create free account
hub / github.com/FreeFem/FreeFem-sources / addPage

Method addPage

plugin/seq/plotPDF.cpp:652–728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

650
651#endif
652
653void SimplePDFModule::addPage( const std::stringstream &ContentStream, const int WIDTH, const int HEIGHT, const int *const MARGIN )
654{
655 const int &marginl = MARGIN[0]; // left
656 const int &marginb = MARGIN[1]; // bottom
657 const int &marginr = MARGIN[2]; // right
658 const int &margint = MARGIN[3]; // top
659
660 //----------------------------------------
661 // PageObject
662 //----------------------------------------
663 std::stringstream strPageObject;
664
665 strPageObject << page_obj_offset+2*page << " 0 obj\n"
666 << "<<\n"
667 << " /Type /Page\n"
668 << " /Parent 3 0 R\n"
669 << " /Resources << /Font << /F1 7 0 R >> >>\n"
670 << " /MediaBox [0 0 " << WIDTH+marginl+marginr << ' ' << HEIGHT+marginb+margint << "]\n"
671 << " /Contents " << page_obj_offset+2*page+1 << " 0 R\n"
672 << ">>\n"
673 << "endobj\n";
674
675 const std::string PageObject = strPageObject.str();
676
677 //----------------------------------------
678 // pageContent (stream)
679 //----------------------------------------
680#ifdef HAVE_ZLIB
681 char *buf;
682 const int compressed_buf_length = deflate_compress( buf, ContentStream.str() );
683#endif
684
685 //----------------------------------------
686 // pageContent (object)
687 //----------------------------------------
688 std::stringstream strContent;
689 strContent << page_obj_offset+2*page+1 << " 0 obj\n"
690 << "<< /Length ";
691#ifdef HAVE_ZLIB
692 strContent << compressed_buf_length << " /Filter /FlateDecode";
693#else
694 strContent << ContentStream.str().length();
695#endif
696 strContent << " >>\n"
697 << "stream\n";
698
699#ifdef HAVE_ZLIB
700 // Following works well even if buf[] has '\0'
701 strContent << std::string( buf+0, buf+compressed_buf_length );
702 delete [] buf;
703#else
704 strContent << ContentStream.str();
705#endif
706
707 strContent << "endstream\n"
708 << "endobj\n";
709

Callers 1

operator()Method · 0.45

Calls 3

lengthMethod · 0.45
push_backMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected