From: Jozef M. <mis...@ho...> - 2010-06-11 19:49:02
|
ack > Our standard general purpose helper createOperator is not sufficient for > simple text operators creation. The main obstacle is that it doesn't have > sufficient information about font which is necessary for proper > unicode->char code conversion. This means that createOperator for text > operators is usable only for a low level usage where the operands already > contain mapped values. > > Let's add createOperatorText helper which contains the complete > information > to do the proper mapping and which then simply calls the low-level > createOperator routine. In order to do that we need the content stream > which > contains GfxResources which contains all fonts and fontName. text is > expected to be unicode encoded. > Index: pdfedit-patches/src/kernel/cpagecontents.cc > =================================================================== > --- pdfedit-patches.orig/src/kernel/cpagecontents.cc 2010-06-11 > 14:12:29.000000000 +0200 > +++ pdfedit-patches/src/kernel/cpagecontents.cc 2010-06-11 > 14:12:29.000000000 +0200 > @@ -517,9 +517,8 @@ CPageContents::addText (const std::strin > PdfOperator::Operands posOperands = _likely_tm; > BT->push_back(createOperator("Tm", posOperands), > getLastOperator(BT)); > - PdfOperator::Operands textOperands; > - textOperands.push_back(shared_ptr<IProperty>(new CString (what))); > - BT->push_back(createOperator("Tj", textOperands), > getLastOperator(BT)); > + shared_ptr<CContentStream> cc = createContentStream(*_page, NULL); > + BT->push_back(createOperatorText(cc, fontName, "TJ", what)); > PdfOperator::Operands emptyOperands; > BT->push_back(createOperator("ET", emptyOperands), > getLastOperator(BT)); > q->push_back(createOperator("Q", emptyOperands), > getLastOperator(q)); > @@ -527,7 +526,7 @@ CPageContents::addText (const std::strin > std::vector<shared_ptr<PdfOperator> > contents; > contents.push_back(q); > - addToBack (contents); > + addToBack (cc, contents); > } > void > Index: pdfedit-patches/src/kernel/pdfoperators.cc > =================================================================== > --- pdfedit-patches.orig/src/kernel/pdfoperators.cc 2010-06-11 > 14:10:50.000000000 +0200 > +++ pdfedit-patches/src/kernel/pdfoperators.cc 2010-06-11 > 14:12:29.000000000 +0200 > @@ -32,6 +32,7 @@ > #include "kernel/ccontentstream.h" > #include "kernel/stateupdater.h" > +#include "kernel/factories.h" > //========================================================== > namespace pdfobjects { > @@ -594,6 +595,42 @@ boost::shared_ptr<PdfOperator> createOpe > return createOperator("cm", ops); > } > +boost::shared_ptr<PdfOperator> createOperatorText > (boost::shared_ptr<CContentStream> &cc, > + const std::string &fontName, const std::string &op, const std::string > &text) > +{ > + utilsPrintDbg(debug::DBG_DBG, ""); > + > + boost::shared_ptr<GfxResources> res = cc->getResources(); > + GfxFont *font = res->lookupFont(fontName.c_str()); > + std::string encText; > + if (font) { > + encText = transformToCodeString(text, font); > + } > + else { > + encText = text; > + utilsPrintDbg(debug::DBG_WARN, "No font found for "+fontName); > + } > + > + PdfOperator::Operands ops; > + > + if (op == "'" || op == "Tj") { > + ops.push_back(boost::shared_ptr<IProperty>(CStringFactory::getInstance(encText))); > + } else if (op == "TJ") { > + boost::shared_ptr<CArray> array(CArrayFactory::getInstance()); > + boost::shared_ptr<IProperty> > str(CStringFactory::getInstance(encText)); > + array->addProperty(*str); > + ops.push_back(array); > + } else if (op == "\"") { > + utilsPrintDbg(debug::DBG_WARN, op+" text operator is not supported"); > + throw NotImplementedException(op +" text operator is not supported"); > + > + }else { > + utilsPrintDbg(debug::DBG_ERR, "Unknown text operator "+op); > + throw ElementBadTypeException("Unknown text operator "+op); > + } > + return createOperator(op, ops); > +} > + > // > //\todo improve performance > // > Index: pdfedit-patches/src/kernel/pdfoperators.h > =================================================================== > --- pdfedit-patches.orig/src/kernel/pdfoperators.h 2010-06-11 > 14:10:50.000000000 +0200 > +++ pdfedit-patches/src/kernel/pdfoperators.h 2010-06-11 > 14:12:29.000000000 +0200 > @@ -325,6 +325,17 @@ boost::shared_ptr<PdfOperator> createOpe > */ > boost::shared_ptr<PdfOperator> createOperatorScale (double width, > double height); > +/** Create a text operator with the font encoding translation. > + * @param cc Content stream wehere the operator will be added (this is > not done by this > + * function - we just reuse resources from it). > + * @param fontName Font for the text. > + * @param op Text operator to use (tj, ' or TJ). > + * @param text Text to be used for the operator (unicode encoded). > + * @throw ElementBadTypeException if an unknown text operator is > provided. > + * @throw NotImplementedException for " text operator. > + */ > +boost::shared_ptr<PdfOperator> createOperatorText > (boost::shared_ptr<CContentStream>& cc, > + const std::string &fontName, const std::string &op, > const std::string &text); > /** Is an operator a composite. */ > inline bool > > > > ------------------------------------------------------------------------------ > ThinkGeek and WIRED's GeekDad team up for the Ultimate > GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the > lucky parental unit. See the prize list and enter to win: > http://p.sf.net/sfu/thinkgeek-promo > _______________________________________________ > Pdfedit-devel mailing list > Pdf...@li... > https://lists.sourceforge.net/lists/listinfo/pdfedit-devel > -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ |