src/lib/EmbeddedFontInfo.h | 4 +- src/lib/MSPUBCollector.cpp | 61 +++++++++++++++++++++++++-------------------- src/lib/MSPUBCollector.h | 2 - src/lib/MSPUBParser.cpp | 24 ++++++++++------- src/lib/MSPUBParser2k.cpp | 2 - src/lib/MSPUBParser97.cpp | 2 - src/lib/PolygonUtils.cpp | 6 ++-- src/lib/ShapeInfo.h | 4 +- 8 files changed, 59 insertions(+), 46 deletions(-)
New commits: commit b99d016d1e43d9ef99c6f3f94a345a189212a117 Author: David Tardon <[email protected]> Date: Fri Dec 26 12:45:57 2014 +0100 simplify this Change-Id: I6a39f76a0019d057b20a4abb29479754ad622b39 diff --git a/src/lib/EmbeddedFontInfo.h b/src/lib/EmbeddedFontInfo.h index f74484a..1200e81 100644 --- a/src/lib/EmbeddedFontInfo.h +++ b/src/lib/EmbeddedFontInfo.h @@ -18,8 +18,8 @@ struct EmbeddedFontInfo { librevenge::RVNGString m_name; librevenge::RVNGBinaryData m_blob; - EmbeddedFontInfo(const librevenge::RVNGString &name) : - m_name(name), m_blob() + EmbeddedFontInfo(const librevenge::RVNGString &name, const librevenge::RVNGBinaryData &data) : + m_name(name), m_blob(data) { } }; diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp index 82a86c0..53ef937 100644 --- a/src/lib/MSPUBCollector.cpp +++ b/src/lib/MSPUBCollector.cpp @@ -105,10 +105,9 @@ static void separateSpacesAndInsertText(librevenge::RVNGDrawingInterface *iface, } // anonymous namespace -librevenge::RVNGBinaryData &MSPUBCollector::addEOTFont(const librevenge::RVNGString &name) +void MSPUBCollector::addEOTFont(const librevenge::RVNGString &name, const librevenge::RVNGBinaryData &data) { - m_embeddedFonts.push_back(EmbeddedFontInfo(name)); - return m_embeddedFonts.back().m_blob; + m_embeddedFonts.push_back(EmbeddedFontInfo(name, data)); } void MSPUBCollector::setShapePictureRecolor(unsigned seqNum, diff --git a/src/lib/MSPUBCollector.h b/src/lib/MSPUBCollector.h index d2d18be..b66e317 100644 --- a/src/lib/MSPUBCollector.h +++ b/src/lib/MSPUBCollector.h @@ -95,7 +95,7 @@ public: // Microsoft "Embedded OpenType" ... need to figure out how to convert // this to a sane format and how to get LibreOffice to understand embedded fonts. - librevenge::RVNGBinaryData &addEOTFont(const librevenge::RVNGString &name); + void addEOTFont(const librevenge::RVNGString &name, const librevenge::RVNGBinaryData &data); void beginGroup(); bool endGroup(); diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp index 9473049..f0e8d65 100644 --- a/src/lib/MSPUBParser.cpp +++ b/src/lib/MSPUBParser.cpp @@ -497,7 +497,7 @@ bool MSPUBParser::parseFontChunk( // skip length, we've already read that // TODO: Why do we not read the data as part of the block info? input->seek(eotOffset.get() + 4, librevenge::RVNG_SEEK_SET); - librevenge::RVNGBinaryData &data = m_collector->addEOTFont(name.get()); + librevenge::RVNGBinaryData data; unsigned long toRead = eotLength; while (toRead > 0 && stillReading(input, (unsigned long)-1)) { @@ -506,6 +506,7 @@ bool MSPUBParser::parseFontChunk( data.append(buf, howManyRead); toRead -= howManyRead; } + m_collector->addEOTFont(name.get(), data); input->seek(subInfo.dataOffset + subInfo.dataLength, librevenge::RVNG_SEEK_SET); } } commit 525d9d714be08629ac8c70bf415f2231c4f910b3 Author: David Tardon <[email protected]> Date: Fri Dec 26 12:41:15 2014 +0100 replace double negation by bool() Change-Id: Ibd72d22c86e8960dd3553fa1406098c8138dae36 diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp index fa199af..82a86c0 100644 --- a/src/lib/MSPUBCollector.cpp +++ b/src/lib/MSPUBCollector.cpp @@ -407,7 +407,7 @@ std::vector<int> MSPUBCollector::getShapeAdjustValues(const ShapeInfo &info) con boost::optional<std::vector<TextParagraph> > MSPUBCollector::getShapeText(const ShapeInfo &info) const { - if (!!info.m_textId) + if (bool(info.m_textId)) { unsigned stringId = info.m_textId.get(); const std::vector<TextParagraph> *ptr_str = getIfExists_const(m_textStringsById, stringId); @@ -424,11 +424,11 @@ void MSPUBCollector::setupShapeStructures(ShapeGroupElement &elt) ShapeInfo *ptr_info = getIfExists(m_shapeInfosBySeqNum, elt.getSeqNum()); if (ptr_info) { - if (!!ptr_info->m_imgIndex) + if (bool(ptr_info->m_imgIndex)) { unsigned index = ptr_info->m_imgIndex.get(); int rot = 0; - if (!!ptr_info->m_innerRotation) + if (bool(ptr_info->m_innerRotation)) rot = ptr_info->m_innerRotation.get(); if (index - 1 < m_images.size()) { @@ -463,7 +463,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co bool hasStroke = false; bool hasBorderArt = false; boost::optional<unsigned> maybeBorderImg = info.m_borderImgIndex; - if (!!maybeBorderImg && !info.m_lines.empty()) + if (bool(maybeBorderImg) && !info.m_lines.empty()) { hasStroke = true; hasBorderArt = true; @@ -482,7 +482,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co librevenge::RVNGString fill = graphicsProps["draw:fill"] ? graphicsProps["draw:fill"]->getStr() : "none"; bool hasFill = fill != "none"; boost::optional<std::vector<TextParagraph> > maybeText = getShapeText(info); - bool hasText = !!maybeText; + bool hasText = bool(maybeText); bool makeLayer = hasBorderArt || (hasStroke && hasFill) || (hasStroke && hasText) || (hasFill && hasText); if (makeLayer) @@ -505,7 +505,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co BorderPosition borderPosition = hasBorderArt ? INSIDE_SHAPE : info.m_borderPosition.get_value_or(HALF_INSIDE_SHAPE); ShapeType type; - if (!!info.m_cropType) + if (bool(info.m_cropType)) { type = info.m_cropType.get(); } @@ -533,7 +533,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co width -= 2 * borderImgWidth; } } - if (!!info.m_pictureRecolor) + if (bool(info.m_pictureRecolor)) { Color obc = info.m_pictureRecolor.get().getFinalColor(m_paletteColors); graphicsProps.insert("draw:color-mode", "greyscale"); @@ -544,10 +544,10 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co graphicsProps.insert("draw:green", static_cast<double>(obc.g) / 255.0, librevenge::RVNG_PERCENT); } - if (!!info.m_pictureBrightness) + if (bool(info.m_pictureBrightness)) graphicsProps.insert("draw:luminance", static_cast<double>(info.m_pictureBrightness.get() + 32768.0) / 65536.0, librevenge::RVNG_PERCENT); bool shadowPropsInserted = false; - if (!!info.m_shadow) + if (bool(info.m_shadow)) { const Shadow &s = info.m_shadow.get(); if (!needsEmulation(s)) @@ -567,14 +567,14 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co writeCustomShape(type, graphicsProps, m_painter, x, y, height, width, true, foldedTransform, std::vector<Line>(), boost::bind(&MSPUBCollector::getCalculationValue, this, info, _1, false, adjustValues), m_paletteColors, info.getCustomShape()); - if (!!info.m_pictureRecolor) + if (bool(info.m_pictureRecolor)) { graphicsProps.remove("draw:color-mode"); graphicsProps.remove("draw:red"); graphicsProps.remove("draw:blue"); graphicsProps.remove("draw:green"); } - if (!!info.m_pictureBrightness) + if (bool(info.m_pictureBrightness)) graphicsProps.remove("draw:luminance"); if (shadowPropsInserted) { @@ -656,7 +656,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co m_painter->drawRectangle(leftRectProps); std::vector<unsigned>::const_iterator iOffset = ba.m_offsets.begin(); boost::optional<Color> oneBitColor; - if (!!info.m_lineBackColor) + if (bool(info.m_lineBackColor)) { oneBitColor = info.m_lineBackColor.get().getFinalColor(m_paletteColors); } @@ -808,7 +808,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co height = strokeCoord.getHeightIn(); width = strokeCoord.getWidthIn(); graphicsProps.insert("draw:fill", "none"); - if (!!info.m_dash && !info.m_dash.get().m_dots.empty()) + if (bool(info.m_dash) && !info.m_dash.get().m_dots.empty()) { const Dash &dash = info.m_dash.get(); graphicsProps.insert("draw:stroke", "dash"); @@ -829,7 +829,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co librevenge::RVNGString dots; dots.sprintf("draw:dots%d", i + 1); graphicsProps.insert(dots.cstr(), static_cast<int>(dash.m_dots[i].m_count)); - if (!!dash.m_dots[i].m_length) + if (bool(dash.m_dots[i].m_length)) { librevenge::RVNGString length; length.sprintf("draw:dots%d-length", i + 1); @@ -869,7 +869,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co props.insert("fo:padding-top", (double)margins.m_top / EMUS_IN_INCH); props.insert("fo:padding-right", (double)margins.m_right / EMUS_IN_INCH); props.insert("fo:padding-bottom", (double)margins.m_bottom / EMUS_IN_INCH); - if (!!info.m_verticalAlign) + if (bool(info.m_verticalAlign)) { switch (info.m_verticalAlign.get()) { @@ -925,7 +925,7 @@ boost::function<void(void)> MSPUBCollector::paintShape(const ShapeInfo &info, co const char *MSPUBCollector::getCalculatedEncoding() const { - if (!!m_calculatedEncoding) + if (bool(m_calculatedEncoding)) { return m_calculatedEncoding.get(); } @@ -996,7 +996,7 @@ void MSPUBCollector::writeImage(double x, double y, boost::optional<Color> oneBitColor) const { librevenge::RVNGPropertyList props; - if (!!oneBitColor) + if (bool(oneBitColor)) { Color obc = oneBitColor.get(); props.insert("draw:color-mode", "greyscale"); @@ -1217,7 +1217,7 @@ void MSPUBCollector::addFont(std::vector<unsigned char> name) librevenge::RVNGPropertyList MSPUBCollector::getParaStyleProps(const ParagraphStyle &style, boost::optional<unsigned> defaultParaStyleIndex) const { ParagraphStyle _nothing; - const ParagraphStyle &defaultStyle = !!defaultParaStyleIndex && defaultParaStyleIndex.get() < m_defaultParaStyles.size() ? m_defaultParaStyles[defaultParaStyleIndex.get()] : _nothing; + const ParagraphStyle &defaultStyle = bool(defaultParaStyleIndex) && defaultParaStyleIndex.get() < m_defaultParaStyles.size() ? m_defaultParaStyles[defaultParaStyleIndex.get()] : _nothing; librevenge::RVNGPropertyList ret; Alignment align = style.m_align.get_value_or( defaultStyle.m_align.get_value_or(LEFT)); @@ -1318,11 +1318,11 @@ librevenge::RVNGPropertyList MSPUBCollector::getCharStyleProps(const CharacterSt { ret.insert("style:text-underline-type", "single"); } - if (!!style.textSizeInPt) + if (bool(style.textSizeInPt)) { ret.insert("fo:font-size", style.textSizeInPt.get() / POINTS_IN_INCH); } - else if (!!defaultCharStyle.textSizeInPt) + else if (bool(defaultCharStyle.textSizeInPt)) { ret.insert("fo:font-size", defaultCharStyle.textSizeInPt.get() / POINTS_IN_INCH); @@ -1339,7 +1339,7 @@ librevenge::RVNGPropertyList MSPUBCollector::getCharStyleProps(const CharacterSt { ret.insert("fo:color", getColorString(Color(0, 0, 0))); // default color is black } - if (!!style.fontIndex && + if (bool(style.fontIndex) && style.fontIndex.get() < m_fonts.size()) { librevenge::RVNGString str; @@ -1347,7 +1347,7 @@ librevenge::RVNGPropertyList MSPUBCollector::getCharStyleProps(const CharacterSt getCalculatedEncoding()); ret.insert("style:font-name", str); } - else if (!!defaultCharStyle.fontIndex && + else if (bool(defaultCharStyle.fontIndex) && defaultCharStyle.fontIndex.get() < m_fonts.size()) { librevenge::RVNGString str; @@ -1437,7 +1437,7 @@ void MSPUBCollector::writePage(unsigned pageSeqNum) const { m_painter->startPage(pageProps); boost::optional<unsigned> masterSeqNum = getMasterPageSeqNum(pageSeqNum); - bool hasMaster = !!masterSeqNum; + bool hasMaster = bool(masterSeqNum); if (hasMaster) { writePageBackground(masterSeqNum.get()); diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp index 364d5b6..9473049 100644 --- a/src/lib/MSPUBParser.cpp +++ b/src/lib/MSPUBParser.cpp @@ -492,7 +492,7 @@ bool MSPUBParser::parseFontChunk( eotLength = subSubInfo.dataLength; } } - if (!!name && !!eotOffset) + if (bool(name) && bool(eotOffset)) { // skip length, we've already read that // TODO: Why do we not read the data as part of the block info? @@ -679,7 +679,7 @@ bool MSPUBParser::parseShape(librevenge::RVNGInputStream *input, rowcolArrayOffset = info.dataOffset; } } - if (!!cellsSeqNum && !!numRows && !!numCols && !!rowcolArrayOffset) + if (bool(cellsSeqNum) && bool(numRows) && bool(numCols) && bool(rowcolArrayOffset)) { unsigned nr = numRows.get(); unsigned nc = numCols.get(); @@ -1515,7 +1515,7 @@ void MSPUBParser::parseEscherShape(librevenge::RVNGInputStream *input, const Esc { maybe_tertiaryFoptValues = extractEscherValues(input, cTertiaryFopt); } - if (!!maybe_tertiaryFoptValues) + if (bool(maybe_tertiaryFoptValues)) { const std::map<unsigned short, unsigned> &tertiaryFoptValues = maybe_tertiaryFoptValues.get(); @@ -1581,7 +1581,7 @@ void MSPUBParser::parseEscherShape(librevenge::RVNGInputStream *input, const Esc } else { - if (!!maybe_tertiaryFoptValues) + if (bool(maybe_tertiaryFoptValues)) { std::map<unsigned short, unsigned> &tertiaryFoptValues = maybe_tertiaryFoptValues.get(); @@ -1698,7 +1698,7 @@ void MSPUBParser::parseEscherShape(librevenge::RVNGInputStream *input, const Esc dotStyle)); } - if (!!maybe_tertiaryFoptValues) + if (bool(maybe_tertiaryFoptValues)) { std::map<unsigned short, unsigned> &tertiaryFoptValues = maybe_tertiaryFoptValues.get(); unsigned *ptr_numColumns = getIfExists(tertiaryFoptValues, FIELDID_NUM_COLUMNS); diff --git a/src/lib/MSPUBParser2k.cpp b/src/lib/MSPUBParser2k.cpp index a206c63..a6ae02b 100644 --- a/src/lib/MSPUBParser2k.cpp +++ b/src/lib/MSPUBParser2k.cpp @@ -447,7 +447,7 @@ bool MSPUBParser2k::parseContents(librevenge::RVNGInputStream *input) bool MSPUBParser2k::parseDocument(librevenge::RVNGInputStream *input) { - if (!!m_documentChunkIndex) + if (bool(m_documentChunkIndex)) { input->seek(m_contentChunks[m_documentChunkIndex.get()].offset, librevenge::RVNG_SEEK_SET); input->seek(0x14, librevenge::RVNG_SEEK_CUR); diff --git a/src/lib/MSPUBParser97.cpp b/src/lib/MSPUBParser97.cpp index 3e4adce..29614ba 100644 --- a/src/lib/MSPUBParser97.cpp +++ b/src/lib/MSPUBParser97.cpp @@ -50,7 +50,7 @@ bool MSPUBParser97::parse() bool MSPUBParser97::parseDocument(librevenge::RVNGInputStream *input) { - if (!!m_documentChunkIndex) + if (bool(m_documentChunkIndex)) { input->seek(m_contentChunks[m_documentChunkIndex.get()].offset + 0x12, librevenge::RVNG_SEEK_SET); unsigned short coordinateSystemMark = readU16(input); diff --git a/src/lib/PolygonUtils.cpp b/src/lib/PolygonUtils.cpp index b6f40ab..9ef8466 100644 --- a/src/lib/PolygonUtils.cpp +++ b/src/lib/PolygonUtils.cpp @@ -6016,7 +6016,7 @@ void writeCustomShape(ShapeType shapeType, librevenge::RVNGPropertyList &graphic bool modifier = cmd.m_command == ELLIPTICALQUADRANTX ? true : false; const Vertex &curr = shape->mp_vertices[vertexIndex]; Vector2D curr2D(x + scaleX * getSpecialIfNecessary(calculator, curr.m_x), y + scaleY * getSpecialIfNecessary(calculator, curr.m_y)); - if (!!lastPoint) + if (bool(lastPoint)) { if (!pathBegin) { @@ -6338,7 +6338,7 @@ void writeCustomShape(ShapeType shapeType, librevenge::RVNGPropertyList &graphic //intentionally no break case ENDSUBPATH: MSPUB_DEBUG_MSG(("ENDSUBPATH\n")); - if (closeEverything && !!pathBegin) + if (closeEverything && bool(pathBegin)) { librevenge::RVNGPropertyList end; end.insert("librevenge:path-action", "Z"); @@ -6359,7 +6359,7 @@ void writeCustomShape(ShapeType shapeType, librevenge::RVNGPropertyList &graphic } if (hasUnclosedElements && closeEverything) { - if (!!pathBegin) + if (bool(pathBegin)) { librevenge::RVNGPropertyList end; end.insert("librevenge:path-action", "Z"); diff --git a/src/lib/ShapeInfo.h b/src/lib/ShapeInfo.h index 4c208ab..d960917 100644 --- a/src/lib/ShapeInfo.h +++ b/src/lib/ShapeInfo.h @@ -78,11 +78,11 @@ struct ShapeInfo } boost::shared_ptr<const CustomShape> getCustomShape() const { - if (!!m_customShape) + if (bool(m_customShape)) { return getFromDynamicCustomShape(m_customShape.get()); } - if (!!m_cropType) + if (bool(m_cropType)) { return boost::shared_ptr<const CustomShape>( libmspub::getCustomShape(m_cropType.get()), commit cc3724d73551b23dc370f865652c14a739e45a00 Author: David Tardon <[email protected]> Date: Fri Dec 26 12:36:13 2014 +0100 handle embedded fonts Change-Id: Ifeb92312aaadf17284c47c25109737cf7ffb6024 diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp index 6a22f17..fa199af 100644 --- a/src/lib/MSPUBCollector.cpp +++ b/src/lib/MSPUBCollector.cpp @@ -1497,6 +1497,16 @@ bool MSPUBCollector::go() addBlackToPaletteIfNecessary(); assignShapesToPages(); m_painter->startDocument(librevenge::RVNGPropertyList()); + + for (std::list<EmbeddedFontInfo>::const_iterator i = m_embeddedFonts.begin(); i != m_embeddedFonts.end(); ++i) + { + librevenge::RVNGPropertyList props; + props.insert("librevenge:name", i->m_name); + props.insert("librevenge:mime-type", "application/vnd.ms-fontobject"); + props.insert("office:binary-data",i->m_blob); + m_painter->defineEmbeddedFont(props); + } + if (m_pageSeqNumsOrdered.empty()) { for (std::map<unsigned, PageInfo>::const_iterator i = m_pagesBySeqNum.begin(); diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp index e7b297c..364d5b6 100644 --- a/src/lib/MSPUBParser.cpp +++ b/src/lib/MSPUBParser.cpp @@ -476,6 +476,7 @@ bool MSPUBParser::parseFontChunk( { boost::optional<librevenge::RVNGString> name; boost::optional<unsigned> eotOffset; + unsigned eotLength = 0; input->seek(subInfo.dataOffset + 4, librevenge::RVNG_SEEK_SET); while (stillReading(input, subInfo.dataOffset + subInfo.dataLength)) { @@ -483,19 +484,21 @@ bool MSPUBParser::parseFontChunk( if (subSubInfo.id == EMBEDDED_FONT_NAME) { name = librevenge::RVNGString(); - appendCharacters(name.get(), subSubInfo.stringData, "UTF-16"); + appendCharacters(name.get(), subSubInfo.stringData, "UTF-16LE"); } else if (subSubInfo.id == EMBEDDED_EOT) { eotOffset = subSubInfo.dataOffset; + eotLength = subSubInfo.dataLength; } } if (!!name && !!eotOffset) { - input->seek(eotOffset.get(), librevenge::RVNG_SEEK_SET); - MSPUBBlockInfo eotRecord = parseBlock(input, true); + // skip length, we've already read that + // TODO: Why do we not read the data as part of the block info? + input->seek(eotOffset.get() + 4, librevenge::RVNG_SEEK_SET); librevenge::RVNGBinaryData &data = m_collector->addEOTFont(name.get()); - unsigned long toRead = eotRecord.dataLength; + unsigned long toRead = eotLength; while (toRead > 0 && stillReading(input, (unsigned long)-1)) { unsigned long howManyRead = 0; _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
