PictSelection::PictSelection (istream& from, State* state) : (nil) { ReadPictGS(from, state); ReadChildren(from, state); valid = from.good(); } // ReadChildren loops determining which kind of Selection follows and // creating it until it reads "end" which means all of the children // have been created. void PictSelection::ReadChildren (istream& from, State* state) { while (from.good()) { Skip(from); Selection* child = nil; from >> buf; if (strcmp(buf, "BSpl") == 0) { child = new BSplineSelection(from, state); } else if (strcmp(buf, "Circ") == 0) { child = new CircleSelection(from, state); } else if (strcmp(buf, "CBSpl") == 0) { child = new ClosedBSplineSelection(from, state); } else if (strcmp(buf, "Elli") == 0) { child = new EllipseSelection(from, state); } else if (strcmp(buf, "Line") == 0) { child = new LineSelection(from, state); } else if (strcmp(buf, "MLine") == 0) { child = new MultiLineSelection(from, state); } else if (strcmp(buf, "Pict") == 0) { child = new PictSelection(from, state); } else if (strcmp(buf, "Poly") == 0) { child = new PolygonSelection(from, state); } else if (strcmp(buf, "Rect") == 0) { child = new RectSelection(from, state); } else if (strcmp(buf, "Text") == 0) { child = new TextSelection(from, state); } else if (strcmp(buf, "eop") == 0) { break; } else { fprintf(stderr, "unknown Selection %s, skipping\n", buf); continue; } if (from.good()) { Append(child); } else { delete child; } } } // WritePicture writes the picture's data and Postscript code to print // it wrapped in Postscript comments that minimally conform to version // 1.0 of Adobe Systems's structuring conventions for Postscript. The // picture must remove itself from its parent if it has a parent to // prevent the parent's transformation from affecting the picture's // calculation of its bounding box. void PictSelection::WritePicture (ostream& to, boolean verbose) { Picture* parent = (Picture*) Parent(); if (parent != nil) { parent->SetCurrent(this); parent->Remove(this); } ScaleToPostscriptCoords(); if (verbose) { WriteComments(to); WritePrologue(to); WriteVersion(to); WriteGridSpacing(to); WriteDrawing(to); WriteTrailer(to); } else { WriteVersion(to); WriteGridSpacing(to); WriteDrawing(to); } ScaleToScreenCoords(); if (parent != nil) { parent->InsertBeforeCur(this); } }
bool ConvertXML2PO(std::string LangDir, std::string LCode, int nPlurals, std::string PluralForm, bool bIsForeignLang) { int stringCount = 0; std::string OutputPOFilename; OutputPOFilename = LangDir + "strings.po"; // Initalize the output po document pPOTFile = fopen (OutputPOFilename.c_str(),"wb"); if (pPOTFile == NULL) { printf("Error opening output file: %s\n", OutputPOFilename.c_str()); return false; } printf("%s\t\t", LCode.c_str()); fprintf(pPOTFile, "# XBMC Media Center language file\n" "%s" "%s%s%s%s%s%s%s%s%s" "msgid \"\"\n" "msgstr \"\"\n" "\"Project-Id-Version: %s\\n\"\n" "\"Report-Msgid-Bugs-To: [email protected]\\n\"\n" "\"POT-Creation-Date: %s\\n\"\n" "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" "\"Language-Team: LANGUAGE\\n\"\n" "\"MIME-Version: 1.0\\n\"\n" "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" "\"Content-Transfer-Encoding: 8bit\\n\"\n" "\"Language: %s\\n\"\n" "\"Plural-Forms: nplurals=%i; plural=%s\\n\"\n", (projType == CORE) ? ("XBMC " + ProjVersion + "\n").c_str() : "", (projType == CORE || projType == UNKNOWN) ? "" : "# Addon Name: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjTextName.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon id: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjName.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon version: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjVersion.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon Provider: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjProvider.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n", (projType == CORE) ? "XBMC-Main" : "XBMC-Addons", GetCurrTime().c_str(), (!LCode.empty()) ? LCode.c_str() : "LANGUAGE", nPlurals, PluralForm.c_str()); bhasLFWritten =false; if (!mapAddonXMLData["en"].strSummary.empty()) { WriteLF(pPOTFile); WriteStrLine("msgctxt ", "Addon Summary", addonXMLEncoding); WriteStrLine("msgid ", mapAddonXMLData["en"].strSummary.c_str(), addonXMLEncoding); WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strSummary.c_str(), addonXMLEncoding); bhasLFWritten =false; stringCount++; } if (!mapAddonXMLData["en"].strDescription.empty()) { WriteLF(pPOTFile); WriteStrLine("msgctxt ", "Addon Description", addonXMLEncoding); WriteStrLine("msgid ", mapAddonXMLData["en"].strDescription.c_str(), addonXMLEncoding); WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strDescription.c_str(), addonXMLEncoding); bhasLFWritten =false; stringCount++; } if (!mapAddonXMLData["en"].strDisclaimer.empty()) { WriteLF(pPOTFile); WriteStrLine("msgctxt ", "Addon Disclaimer", addonXMLEncoding); WriteStrLine("msgid ", mapAddonXMLData["en"].strDisclaimer.c_str(), addonXMLEncoding); WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strDisclaimer.c_str(), addonXMLEncoding); bhasLFWritten =false; stringCount++; } // if (projType == ADDON_NOSTRINGS) // return true; int previd = -1; for (itSourceXmlId = mapSourceXmlId.begin(); itSourceXmlId != mapSourceXmlId.end(); itSourceXmlId++) { int id = itSourceXmlId->first; std::string value = itSourceXmlId->second; bhasLFWritten = false; //create comment lines, if empty string id or ids found and //re-create original xml comments between entries. Only for the source language if (!bIsForeignLang) WriteComments(previd, true); if ((id-previd >= 2) && !bIsForeignLang && previd > -1) { WriteLF(pPOTFile); if (id-previd == 2) fprintf(pPOTFile,"#empty string with id %i\n", id-1); if (id-previd > 2) fprintf(pPOTFile,"#empty strings from id %i to %i\n", previd+1, id-1); } bhasLFWritten = false; //write comment originally placed next to the string entry //convert it into #. style gettext comment if (!bIsForeignLang) WriteComments(id, false); //create msgctxt, including the string id WriteLF(pPOTFile); fprintf(pPOTFile,"msgctxt \"#%i\"\n", id); //create msgid and msgstr lines WriteLF(pPOTFile); WriteStrLine("msgid ", value.c_str(), sourceXMLEncoding); if (bIsForeignLang) { itForeignXmlId = mapForeignXmlId.find(id); if (itForeignXmlId != mapForeignXmlId.end()) { stringCount++; WriteStrLine("msgstr ", itForeignXmlId->second.c_str(), foreignXMLEncoding); } else fprintf(pPOTFile,"msgstr \"\"\n"); } else fprintf(pPOTFile,"msgstr \"\"\n"); if (!bIsForeignLang) stringCount++; previd =id; } fclose(pPOTFile); printf("%i\t\t", stringCount); printf("%s\n", OutputPOFilename.erase(0,WorkingDir.length()).c_str()); mapForeignXmlId.clear(); return true; }
bool ConvertXML2PO(std::string LangDir, std::string LCode, int nPlurals, std::string PluralForm, bool bIsForeignLang) { int contextCount = 0; int stringCountSource = 0; int stringCountForeign = 0; std::string OutputPOFilename; OutputPOFilename = LangDir + "strings.po"; // Initalize the output po document pPOTFile = fopen (OutputPOFilename.c_str(),"wb"); if (pPOTFile == NULL) { printf("Error opening output file: %s\n", OutputPOFilename.c_str()); return false; } printf("%s\t\t", LCode.c_str()); fprintf(pPOTFile, "# XBMC Media Center language file\n" "msgid \"\"\n" "msgstr \"\"\n" "\"Project-Id-Version: %s-%s\\n\"\n" "\"Report-Msgid-Bugs-To: [email protected]\\n\"\n" "\"POT-Creation-Date: %s\\n\"\n" "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" "\"Language-Team: LANGUAGE\\n\"\n" "\"MIME-Version: 1.0\\n\"\n" "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" "\"Content-Transfer-Encoding: 8bit\\n\"\n" "\"Language: %s\\n\"\n" "\"Plural-Forms: nplurals=%i; plural=%s\\n\"\n\n", (pProjectName != NULL) ? pProjectName : "xbmc-unnamed", (pVersionNumber != NULL) ? pVersionNumber : "rev_unknown", GetCurrTime().c_str(), (!LCode.empty()) ? LCode.c_str() : "LANGUAGE", nPlurals, PluralForm.c_str()); int previd = -1; bool bCommentWritten = false; for (itSourceXmlId = mapSourceXmlId.begin(); itSourceXmlId != mapSourceXmlId.end(); itSourceXmlId++) { int id = itSourceXmlId->first; std::string value = itSourceXmlId->second; //create comment lines, if empty string id or ids found and //re-create original xml comments between entries. Only for the source language bCommentWritten = false; if (!bIsForeignLang) bCommentWritten = WriteComments(previd, true); if ((id-previd >= 2) && !bIsForeignLang) { if (id-previd == 2 && previd > -1) fprintf(pPOTFile,"#empty string with id %i\n", id-1); if (id-previd > 2 && previd > -1) fprintf(pPOTFile,"#empty strings from id %i to %i\n", previd+1, id-1); bCommentWritten = true; } if (bCommentWritten) fprintf(pPOTFile, "\n"); //create comment, including string id fprintf(pPOTFile,"#: id:%i\n", id); //write comment originally placed next to the string entry //convert it into #. style gettext comment if (!bIsForeignLang) WriteComments(id, false); if (multimapSourceXmlStrings.count(value) > 1) // if we have multiple IDs for the same string value { //create autogenerated context message for multiple msgid entries fprintf(pPOTFile,"msgctxt \"Auto context with id %i\"\n", id); contextCount++; } //create msgid and msgstr lines WriteStrLine("msgid ", value.c_str(), sourceXMLEncoding); if (bIsForeignLang) { itForeignXmlId = mapForeignXmlId.find(id); if (itForeignXmlId != mapForeignXmlId.end()) { stringCountForeign++; WriteStrLine("msgstr ", itForeignXmlId->second.c_str(), foreignXMLEncoding); fprintf(pPOTFile,"\n"); } else fprintf(pPOTFile,"msgstr \"\"\n\n"); } else fprintf(pPOTFile,"msgstr \"\"\n\n"); stringCountSource++; previd =id; } fclose(pPOTFile); printf("%i\t\t", bIsForeignLang ? stringCountForeign : stringCountSource); printf("%i\t\t", contextCount); printf("%s\n", OutputPOFilename.erase(0,WorkingDir.length()).c_str()); mapForeignXmlId.clear(); return true; }