예제 #1
0
void IE_Imp_WordPerfect::openFootnote(const librevenge::RVNGPropertyList & /*propList*/)
{
	if (m_bHdrFtrOpenCount) return; // HACK

	if (!m_bInSection)
	{
		X_CheckDocumentError(appendStrux(PTX_Section, PP_NOPROPS));
		X_CheckDocumentError(appendStrux(PTX_Block,PP_NOPROPS));
		m_bInSection = true;
	}

	std::string footnoteId = UT_std_string_sprintf("%i", UT_rand());

	PP_PropertyVector propsArray = {
		"type",	"footnote_ref",
		"footnote-id", footnoteId
	};
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));

	const PP_PropertyVector attribs = {
		"footnote-id", footnoteId
	};
	X_CheckDocumentError(appendStrux(PTX_SectionFootnote, attribs));

	X_CheckDocumentError(appendStrux(PTX_Block, PP_NOPROPS));
	m_bRequireBlock = false;

	// just change the type.
	propsArray[1] = "footnote_anchor";
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));
}
void IE_Imp_WordPerfect::openEndnote(const WPXPropertyList & /*propList*/)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	const gchar** propsArray = NULL;
	
	UT_String endnoteId;
	UT_String_sprintf(endnoteId,"%i",UT_rand());	
	
	propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *)));
	propsArray [0] = "type";
	propsArray [1] = "endnote_ref";
	propsArray [2] = "endnote-id";
	propsArray [3] = endnoteId.c_str();
	propsArray [4] = NULL;
	propsArray [5] = NULL;
	propsArray [6] = NULL;
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));

	const gchar * attribs[3] ={"endnote-id", endnoteId.c_str(), NULL};
	X_CheckDocumentError(appendStrux(PTX_SectionEndnote,attribs));
	
	X_CheckDocumentError(appendStrux(PTX_Block,NULL));
	m_bRequireBlock = false;

	propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *)));
	propsArray [0] = "type";
	propsArray [1] = "endnote_anchor";
	propsArray [2] = "endnote-id";
	propsArray [3] = endnoteId.c_str();
	propsArray [4] = NULL;
	propsArray [5] = NULL;
	propsArray [6] = NULL;
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));
}
예제 #3
0
파일: Object.cpp 프로젝트: ripple/rippled
void Array::append (Json::Value const& v)
{
    auto t = v.type();
    switch (t)
    {
    case Json::nullValue:
        return append (nullptr);
    case Json::intValue:
        return append (v.asInt());
    case Json::uintValue:
        return append (v.asUInt());
    case Json::realValue:
        return append (v.asDouble());
    case Json::stringValue:
        return append (v.asString());
    case Json::booleanValue:
        return append (v.asBool());

    case Json::objectValue:
    {
        auto object = appendObject ();
        copyFrom (object, v);
        return;
    }

    case Json::arrayValue:
    {
        auto array = appendArray ();
        for (auto& item: v)
            array.append (item);
        return;
    }
    }
    assert (false);  // Can't get here.
}
예제 #4
0
 void testFailureArray()
 {
     {
         setup ("array failure append");
         auto& root = makeRoot();
         auto array = root.setArray ("array");
         auto subarray = array.appendArray ();
         auto fail = [&]() { array.append ("fail"); };
         expectException (fail);
     }
     {
         setup ("array failure appendArray");
         auto& root = makeRoot();
         auto array = root.setArray ("array");
         auto subarray = array.appendArray ();
         auto fail = [&]() { array.appendArray (); };
         expectException (fail);
     }
     {
         setup ("array failure appendObject");
         auto& root = makeRoot();
         auto array = root.setArray ("array");
         auto subarray = array.appendArray ();
         auto fail = [&]() { array.appendObject (); };
         expectException (fail);
     }
 }
예제 #5
0
void LevelEditor::importObjectLayout(int levelHeaderIndex__) {
  if (currentObjectGroup() == NULL) {
    return;
  }

  clearCurrentLevelObjects();
                      
  AreaMapReference mapnums = mapData_.levelHeaders()
    .areaMapNumOfIndex(levelHeaderIndex__);
  
  // areas with no layout
  if ((mapnums.areaNum() == 16) || (mapnums.areaNum() == 19)) {
    return;
  }
  
  int objectIndex
    = levelObjectEntryGroups_.indexOfMapnum(
                      mapnums.areaNum(),
                      mapnums.mapNum());
  
  LevelObjectEntryGroup& group
      = levelObjectEntryGroups_.group(objectIndex);
  
  for (LevelObjectEntryCollection::iterator it = group.begin();
       it != group.end();
       ++it) {
    appendObject(*it);
  }
}
예제 #6
0
result_t MongoCollection::runCommand(exlib::string cmd,
    v8::Local<v8::Object> arg, v8::Local<v8::Object>& retVal)
{
    obj_ptr<MongoDB> db(m_db);
    if (!db)
        return CHECK_ERROR(CALL_E_INVALID_CALL);

    bson bbq;

    bson_init(&bbq);
    bson_append_string(&bbq, cmd.c_str(), m_name.c_str());
    if (!appendObject(holder(), &bbq, arg)) {
        bson_destroy(&bbq);
        return CHECK_ERROR(CALL_E_INVALIDARG);
    }
    bson_finish(&bbq);

    return db->bsonHandler(&bbq, retVal);
}
예제 #7
0
void GenericDataCollection::insertRow(const int i, GenericDataObject *obj)
{
  if (obj != nullptr)
  {
    int id = obj->getValue("id").toInt();
    if (i < 0) {
      delete obj;
    }
    else if (i >= m_sortedIDs.size())
    {
      appendObject(id, obj);
    }
    else
    {
      m_sortedIDs.insert(i, id);
      m_objects.insert(id, obj);
    }
  }
}
예제 #8
0
instances_dlg::instances_dlg(QWidget * parent) : QDialog(parent)
{
	debugQt("instances_dlg::instances_dlg()");
	this->setAttribute(Qt::WA_DeleteOnClose);
	compteur_objet++;
	this->setWindowTitle("view instances");
	this->setGeometry(QRect(330, 120, 112, 68));

	layoutV = new QVBoxLayout(this);

	appendObject(&instances_dlg::compteur_objet,"instances_dlg"); // this
	
	this->setLayout(layoutV);

	timer = new QTimer (this);
	connect(timer, SIGNAL(timeout()), this, SLOT(slotTimer()));
	timer->start(1500);
	slotTimer(); 
}
예제 #9
0
/*!  
 * Get all paragraph-related attributes and add them to the document.
 *
 * It does an appendStrux setting the current paragraph attributes and opening
 * a new paragraph. Several special cases are handled here too, mostly for
 * bullets.
 */
UT_Error IE_Imp_Psion::applyParagraphAttributes(const psiconv_paragraph_layout layout,
                      const gchar *stylename)
{
	UT_return_val_if_fail(layout != NULL, true /* perhaps should be false, but we want loading to proceed */);

	UT_UTF8String props;
	UT_Error res;

	// Get all attributes into prop
	if ((res = getParagraphAttributes(layout,props)))
		return UT_IE_IMPORTERROR;

	// HACK: Handle bullets
	// This is really, really ugly.
	// We can not really select the bullet symbol to use, so we do not even
	// try and just use always the plain round bullet.
	// Indent magic is done in getParagraphAttributes.
	if (layout->bullet->on) {
		props += ";list-style:Bullet List;field-font:Symbol";
		// We need to generate the list once, but only if we actually
		// have a bullet somewhere. Nasty. The attributes are mostly
		// black magickish...
		if (!list) {
			list = true;
			const PP_PropertyVector propsArray = {
				"id", global_listid,
				"parentid",	"0",
				"type",	"5",
				"start-value", "0",
				"list-delim", "%L",
				"list-decimal",	"NULL"
			};
			getDoc()->appendList(propsArray);
		}
	}

	// Prepare the properties for this paragraph strux
	UT_DEBUGMSG(("PSION: Paragraph: %s\n",props.utf8_str()));
	PP_PropertyVector propsArray = {
		"props", props.utf8_str(),
		"style", stylename
	};

	// Bullets need the listid too.
	if (layout->bullet->on) {
		propsArray.push_back("listid");
		propsArray.push_back(global_listid);
	}

	if (!(appendStrux(PTX_Block, propsArray))) {
		return UT_IE_IMPORTERROR;
	}

	// HACK: there is no real setting to do this. Yet.
	if (layout->on_next_page) {
		UT_UCSChar ucs = UCS_FF;
		if (!(appendSpan(&ucs,1)))
			return UT_IE_IMPORTERROR;
	}

	// We need to append a field and some other stuff...
	if (layout->bullet->on) {
		propsArray.resize(2);
		propsArray.push_back("type");
		propsArray.push_back("list_label");

		if (!(appendObject(PTO_Field,propsArray)))
			return UT_IE_IMPORTERROR;

		// In some cases, but not in all, we need a tab after the bullet.
		// See the Psiconv docs for the (ugly) details.
		if ((!layout->bullet->indent && (layout->indent_first > 0)) || 
			layout->bullet->indent) {
			UT_UCSChar uc = (UT_UCSChar) UCS_TAB;
			if (!(appendSpan(&uc,1)))
				return UT_IE_IMPORTERROR;
		}
	}
	return UT_OK;
}
예제 #10
0
// ASSUMPTION: We assume that unordered lists will always pass a number of "0". unpredictable behaviour
// may result otherwise
void IE_Imp_WordPerfect::openListElement(const librevenge::RVNGPropertyList &propList)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	UT_DEBUGMSG(("AbiWordPerfect: openListElement\n"));
	
	UT_ASSERT(m_pCurrentListDefinition); // FIXME: ABI_LISTS_IMPORT throw an exception back to libwpd, if this fails
	
	// Paragraph properties for our list element
	UT_String szListID;
	UT_String szParentID;
	UT_String szLevel;
	UT_String_sprintf(szListID,"%d",m_pCurrentListDefinition->getListID(m_iCurrentListLevel));
	if (m_iCurrentListLevel > 1) 
		UT_String_sprintf(szParentID,"%d", m_pCurrentListDefinition->getListID((m_iCurrentListLevel-1)));
	else
		UT_String_sprintf(szParentID,"0"); 
	UT_String_sprintf(szLevel,"%d", m_iCurrentListLevel);
	
	const gchar* listAttribs[PT_MAX_ATTRIBUTES*2 + 1];
	UT_uint32 attribsCount=0;
	
	listAttribs[attribsCount++] = PT_LISTID_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = szListID.c_str();
	listAttribs[attribsCount++] = PT_PARENTID_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = szParentID.c_str();
	listAttribs[attribsCount++] = PT_LEVEL_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = szLevel.c_str();
	
	// Now handle the Abi List properties
	UT_String propBuffer;
	UT_String tempBuffer;
	UT_String_sprintf(tempBuffer,"list-style:%i;", m_pCurrentListDefinition->getListType(m_iCurrentListLevel));
	propBuffer += tempBuffer;

#if 0
	// FIXME: writing the list delimiter is kind of tricky and silly (because wordperfect wants to define
	// it within the document, while abi wants to (sensibly probably) define it in the list definition)
	// (we reset it each time but only for numbered lists)
	if (listDefinition->isLevelNumbered(m_iCurrentListLevel)) 
	{  
		UT_DEBUGMSG(("WordPerfect: Appending this list delim: %s\n", m_rightListDelim.c_str()));
		listDefinition->setListRightDelimText(m_iCurrentListLevel, m_rightListDelim.c_str());
		X_CheckWordPerfectError(_updateDocumentListDefinition(listDefinition, m_iCurrentListLevel));
	}
#endif

	if (m_pCurrentListDefinition->getListType(m_iCurrentListLevel) == BULLETED_LIST)
		UT_String_sprintf(tempBuffer, "field-font:Symbol; ");
	else
		UT_String_sprintf(tempBuffer, "field-font:NULL; ");
	
	m_pCurrentListDefinition->incrementLevelNumber(m_iCurrentListLevel);
	
	propBuffer += tempBuffer;
	UT_String_sprintf(tempBuffer, "start-value:%i; ", 1);
	propBuffer += tempBuffer;

	UT_String_sprintf(tempBuffer, "margin-left:%.4fin; ", m_pCurrentListDefinition->getListLeftOffset(m_iCurrentListLevel)
					+ m_pCurrentListDefinition->getListMinLabelWidth(m_iCurrentListLevel)
					- (propList["fo:text-indent"] ? propList["fo:text-indent"]->getDouble() : 0.0f));
	propBuffer += tempBuffer;
	UT_String_sprintf(tempBuffer, "text-indent:%.4fin", - m_pCurrentListDefinition->getListMinLabelWidth(m_iCurrentListLevel)
					+ (propList["fo:text-indent"] ? propList["fo:text-indent"]->getDouble() : 0.0f));
	propBuffer += tempBuffer;

	listAttribs[attribsCount++] = PT_PROPS_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = propBuffer.c_str();
	listAttribs[attribsCount++] = NULL;

	X_CheckDocumentError(appendStrux(PTX_Block, PP_std_copyProps(listAttribs)));
	m_bRequireBlock = false;

	// hang text off of a list label
	getDoc()->appendFmtMark();
	UT_DEBUGMSG(("WordPerfect: LISTS - Appended a list tag def'n (character props)\n"));

	// append a list field label
	PP_PropertyVector fielddef = {
		"type", "list_label"
	};
	X_CheckDocumentError(appendObject(PTO_Field,fielddef));
	UT_DEBUGMSG(("WordPerfect: LISTS - Appended a field def'n\n"));

	// insert a tab
	UT_UCS4Char ucs = UCS_TAB;
	X_CheckDocumentError(appendSpan(&ucs,1));
}
bool IE_Imp_MSWrite::read_txt (int from, int to)
{
	static const char *currcp;
	int fcMac, pnChar, fcFirst, cfod, fc, fcLim;
	unsigned char page[0x80];
	UT_String properties, tmp;
	int dataLen = static_cast<UT_sint32>(mData.getLength());

	UT_DEBUGMSG(("    TXT:\n"));
	UT_DEBUGMSG(("     from = %d\n", from));
	UT_DEBUGMSG(("     to   = %d\n", to));

	fcMac = wri_struct_value(wri_file_header, "fcMac");
	pnChar = (fcMac + 127) / 128;

	fcFirst = 0x80;

	while (true)
	{
		gsf_input_seek(mFile, pnChar++ * 0x80, G_SEEK_SET);
		gsf_input_read(mFile, 0x80, page);

		fc = READ_DWORD(page);
		cfod = page[0x7f];

		UT_DEBUGMSG(("      fcFirst = %d\n", fc));
		UT_DEBUGMSG(("      cfod    = %d\n", cfod));

		if (fc != fcFirst) UT_WARNINGMSG(("read_txt: fcFirst wrong.\n"));

		// read all FODs (format descriptors)
		for (int fod = 0; fod < cfod; fod++)
		{
			int bfprop, cch, ftc, hps, fBold, fItalic, fUline, hpsPos;

			UT_DEBUGMSG(("       CHP-FOD #%02d:\n", fod + 1));

			// read a FOD (format descriptor)
			fcLim = READ_DWORD(page + 4 + fod * 6);
			bfprop = READ_WORD(page + 8 + fod * 6);

			UT_DEBUGMSG(("        fcLim  = %d\n", fcLim));
			UT_DEBUGMSG((bfprop == 0xffff ? "        bfprop = 0x%04X\n" : "        bfprop = %d\n", bfprop));

			// default CHP values
			ftc = 0;
			hps = 24;
			fBold = fItalic = fUline = hpsPos = 0;

			// if the CHP FPROPs (formatting properties) differ from the defaults, get them
			if (bfprop != 0xffff && bfprop + (cch = page[bfprop + 4]) < 0x80)
			{
				UT_DEBUGMSG(("         cch = %d\n", cch));

				if (cch >= 2) ftc = page[bfprop + 6] >> 2;
				if (cch >= 5) ftc |= (page[bfprop + 9] & 3) << 6;
				if (cch >= 3) hps = page[bfprop + 7];
				if (cch >= 2) fBold = page[bfprop + 6] & 1;
				if (cch >= 2) fItalic = page[bfprop + 6] & 2;
				if (cch >= 4) fUline = page[bfprop + 8] & 1;
				if (cch >= 6) hpsPos = page[bfprop + 10];
			}

			UT_DEBUGMSG(("         ftc           = %d\n", ftc));
			UT_DEBUGMSG(("         hps           = %d\n", hps));
			UT_DEBUGMSG(("         fBold         = %d\n", fBold));
			UT_DEBUGMSG(("         fItalic       = %d\n", fItalic));
			UT_DEBUGMSG(("         fUline        = %d\n", fUline));
			UT_DEBUGMSG(("         hpsPos        = %d\n", hpsPos));

			if (ftc >= wri_fonts_count)
			{
				UT_WARNINGMSG(("read_txt: Wrong font code.\n"));
				ftc = wri_fonts_count - 1;
			}

			if (from < fcLim && to >= fcFirst)
			{
				UT_LocaleTransactor lt(LC_NUMERIC, "C");
				UT_String_sprintf(properties, "font-weight:%s",
				                              fBold ? "bold" : "normal");

				if (hps != 24)
				{
					UT_String_sprintf(tmp, "; font-size:%dpt", hps / 2);
					properties += tmp;
				}

				if (fItalic) properties += "; font-style:italic";
				if (fUline) properties += "; text-decoration:underline";

				if (hpsPos)
				{
					UT_String_sprintf(tmp, "; text-position:%s",
					                       hpsPos < 128 ? "superscript" : "subscript");
					properties += tmp;
				}

				if (wri_fonts_count)
				{
					UT_String_sprintf(tmp, "; font-family:%s", wri_fonts[ftc].name);
					properties += tmp;
				}

				if (wri_fonts[ftc].codepage != currcp /*sic!*/)
				{
					set_codepage(wri_fonts[ftc].codepage);
					currcp = wri_fonts[ftc].codepage;
				}

				mText.clear();
				UT_DEBUGMSG(("         Text: "));

				while (fcFirst <= from && from < fcLim && from <= to && from - 0x80 < dataLen)
					translate_char(*mData.getPointer(from++ - 0x80), mText);

				UT_DEBUGMSG(("\n"));

				// new attributes, only if there was text
				if (mText.size() > 0)
				{
					const gchar *attributes[5];
					const UT_UCS4Char *text = mText.ucs4_str(), *p = text;
					size_t txtLen;

					UT_DEBUGMSG(("         Conv: %s\n", mText.utf8_str()));

					attributes[0] = PT_PROPS_ATTRIBUTE_NAME;
					attributes[1] = properties.c_str();
					attributes[2] = NULL;

					appendFmt(attributes);

					// check for page number (should only be in header or footer)
					while (*p && *p != (UT_UCS4Char) 0x01) p++;

					if (*p)
					{
						if (p - text) appendSpan(text, p - text);

						attributes[2] = PT_TYPE_ATTRIBUTE_NAME;
						attributes[3] = "page_number";
						attributes[4] = NULL;

						appendObject(PTO_Field, attributes);

						txtLen = mText.size() - (p - text) - 1;
						p++;
					}
					else
					{
						txtLen = mText.size();
						p = text;
					}

					if (txtLen) appendSpan(p, txtLen);
				}
			}

			fcFirst = fcLim;

			if (fcLim >= fcMac || fcFirst > to)
			{
				UT_DEBUGMSG(("       CHP-FODs end, fcLim (%d) >= fcMac (%d) or fcFirst (%d) > to (%d)\n", fcLim, fcMac, fcFirst, to));
				return true;
			}
		}
	}
예제 #12
0
static std::unique_ptr<SkPDFDict> gradientStitchCode(const SkShader::GradientInfo& info) {
    auto retval = SkPDFMakeDict();

    // normalize color stops
    int colorCount = info.fColorCount;
    std::vector<SkColor>  colors(info.fColors, info.fColors + colorCount);
    std::vector<SkScalar> colorOffsets(info.fColorOffsets, info.fColorOffsets + colorCount);

    int i = 1;
    while (i < colorCount - 1) {
        // ensure stops are in order
        if (colorOffsets[i - 1] > colorOffsets[i]) {
            colorOffsets[i] = colorOffsets[i - 1];
        }

        // remove points that are between 2 coincident points
        if ((colorOffsets[i - 1] == colorOffsets[i]) && (colorOffsets[i] == colorOffsets[i + 1])) {
            colorCount -= 1;
            colors.erase(colors.begin() + i);
            colorOffsets.erase(colorOffsets.begin() + i);
        } else {
            i++;
        }
    }
    // find coincident points and slightly move them over
    for (i = 1; i < colorCount - 1; i++) {
        if (colorOffsets[i - 1] == colorOffsets[i]) {
            colorOffsets[i] += 0.00001f;
        }
    }
    // check if last 2 stops coincide
    if (colorOffsets[i - 1] == colorOffsets[i]) {
        colorOffsets[i - 1] -= 0.00001f;
    }

    SkAutoSTMalloc<4, ColorTuple> colorDataAlloc(colorCount);
    ColorTuple *colorData = colorDataAlloc.get();
    for (int i = 0; i < colorCount; i++) {
        colorData[i][0] = SkColorGetR(colors[i]);
        colorData[i][1] = SkColorGetG(colors[i]);
        colorData[i][2] = SkColorGetB(colors[i]);
    }

    // no need for a stitch function if there are only 2 stops.
    if (colorCount == 2)
        return createInterpolationFunction(colorData[0], colorData[1]);

    auto encode = SkPDFMakeArray();
    auto bounds = SkPDFMakeArray();
    auto functions = SkPDFMakeArray();

    retval->insertObject("Domain", SkPDFMakeArray(0, 1));
    retval->insertInt("FunctionType", 3);

    for (int i = 1; i < colorCount; i++) {
        if (i > 1) {
            bounds->appendScalar(colorOffsets[i-1]);
        }

        encode->appendScalar(0);
        encode->appendScalar(1.0f);

        functions->appendObject(createInterpolationFunction(colorData[i-1], colorData[i]));
    }

    retval->insertObject("Encode", std::move(encode));
    retval->insertObject("Bounds", std::move(bounds));
    retval->insertObject("Functions", std::move(functions));

    return retval;
}