public override bool Equals(object obj) { if (!(obj is SymbolText)) { return(false); } SymbolText other = obj as SymbolText; if (other.Text != Text) { return(false); } if (other.Lang != Lang) { return(false); } if (other.Plural != Plural) { return(false); } if (other.Gender != Gender) { return(false); } if (other.Case != Case) { return(false); } if (other.CaseOfModified != CaseOfModified) { return(false); } return(true); }
// Update the data from the current state of the right hand side controls void UpdateDataFromControls(string id) { if (checkBoxShowKey.Enabled) { customSymbolKey[id] = checkBoxShowKey.Checked; } if (useAsLocalizeTool) { SymbolText symText = new SymbolText(); symText.Lang = LangId; symText.Text = textBoxSymbolName.Text; if (!symbolNames.ContainsKey(id)) { symbolNames[id] = new List <SymbolText>(); } List <SymbolText> list = symbolNames[id]; int index = list.FindIndex(st => (st.Lang == LangId)); if (index >= 0) { list[index] = symText; } else { list.Add(symText); } } }
// Find the best matching SymbolText. Gender can be null or empty for don't care. Same with nounCase. If // nounCase is empty then the first noun case from the language is chosen if possible. static SymbolText FindBestText(SymbolDB symbolDB, List <SymbolText> texts, string language, bool plural, string gender, string nounCase) { int best = 99999; SymbolText bestSymText = null; if (gender == null) { gender = ""; } string defaultNounCase = ""; SymbolLanguage symbolLanguage = symbolDB.GetLanguage(language); if (symbolLanguage != null && symbolLanguage.CaseModifiers && symbolLanguage.Cases.Length > 0) { defaultNounCase = symbolLanguage.Cases[0]; } // Search for exact match. foreach (SymbolText symtext in texts) { int metric = 0; if (symtext.Lang != language && symtext.Lang != "en") { metric += 100; } if (symtext.Lang != language && symtext.Lang == "en") // english is most preferred if no language match { metric += 50; } if (symtext.Plural != plural) { metric += 10; } if (gender != "" && symtext.Gender != gender) { metric += 5; } if (nounCase != "" && symtext.Case != nounCase) { metric += 3; } if (nounCase == "" && symtext.Case != null && symtext.Case != defaultNounCase) { metric += 1; } if (metric < best) { best = metric; bestSymText = symtext; } } return(bestSymText); }
// Read the values in the grid into symbolTexts. void ReadGrid() { List <SymbolText> symtexts = new List <SymbolText>(); foreach (DataGridViewRow row in dataGridView.Rows) { SymbolText text = new SymbolText(); text.Lang = symLanguage.LangId; text.Text = UnsanitizeFillIn((string)row.Cells[3].Value); if (genderColumn.Visible) { text.Gender = (string)row.Cells[1].Value; } else if (showGenderList) { text.Gender = comboBoxGenderChooser.Text; } else { text.Gender = ""; } if (numberColumn.Visible) { text.Plural = (string)row.Cells[0].Value == MiscText.Plural; } else { text.Plural = false; } if (caseColumn.Visible) { text.Case = (string)row.Cells[2].Value; } if (showCaseList) { if (comboBoxCaseChooser.SelectedIndex <= 0) { text.CaseOfModified = ""; } else { text.CaseOfModified = (string)comboBoxCaseChooser.SelectedItem; } } symtexts.Add(text); } symbolTexts = symtexts; }
/// <summary> /// Get the plural text for the symbol to use in text descriptions. If no plural text is defined, /// the singular text is used instead. /// </summary> /// <param name="language">The language to use.</param> /// <returns>The text string to use.</returns> public string GetPluralText(string language, string gender = null, string nounCase = "") { SymbolText best = FindBestText(symbolDB, texts, language, true, gender, nounCase); if (best != null) { return(best.Text); } else { return(null); } }
// Get the case of what this symbol modifies, or "" if none. public static string GetModifiedCase(SymbolDB symbolDB, List <SymbolText> texts, string language) { SymbolText best = FindBestText(symbolDB, texts, language, false, "", ""); if (best != null) { return(best.CaseOfModified); } else { return(null); } }
// Get the best symbol text for a language from a list of symbol texts. public static string GetBestSymbolText(SymbolDB symbolDB, List <SymbolText> texts, string language, bool plural, string gender, string nounCase) { SymbolText best = FindBestText(symbolDB, texts, language, plural, gender, nounCase); if (best != null) { return(best.Text); } else { return(null); } }
// Get the gender for a item from a list of symbol texts. public static string GetSymbolGender(SymbolDB symbolDB, List <SymbolText> texts, string language) { SymbolText best = FindBestText(symbolDB, texts, language, false, "", ""); if (best != null) { return(best.Gender); } else { return(null); } }
// Get the gender of this item. public string GetGender(string language) { SymbolText best = FindBestText(symbolDB, texts, language, false, null, ""); if (best != null) { return(best.Gender); } else { return(null); } }
// Copy all names from one language to another. private void CopyAllNames(string langIdFrom, string langIdTo) { XmlNodeList allNames = root.SelectNodes(string.Format("/symbols/symbol/name[@lang='{0}']", langIdFrom)); HashSet <string> handledSymbolsIds = new HashSet <string>(); foreach (XmlNode node in allNames) { SymbolText symText = new SymbolText(); symText.ReadFromXmlElementNode((XmlElement)node); symText.Lang = langIdTo; string symbolId = ((XmlElement)node.ParentNode).GetAttribute("id"); if (!handledSymbolsIds.Contains(symbolId)) { AddOneSymbolName(symbolId, symText); handledSymbolsIds.Add(symbolId); } } }
// Add one symbol name. private void AddOneSymbolName(string symbolId, SymbolText symbolText) { symbolText.Plural = false; symbolText.Gender = ""; // Find existing symbol, for this symbolId. Could be more than one for ones that have different ones for different standards. XmlNodeList symbolNodes = root.SelectNodes(string.Format("/symbols/symbol[@id='{0}']", symbolId)); foreach (XmlNode symbolNode in symbolNodes) { // The new node to insert/replace. XmlNode newNode = symbolText.CreateXmlElement(xmldoc, "name"); // Add new name node symbolNode.PrependChild(newNode); symbolNode.InsertBefore(xmldoc.CreateTextNode("\r\n\t\t"), newNode); } }
// Copy all texts from one language to another. private void CopyAllTexts(string langIdFrom, string langIdTo) { XmlNodeList allTexts = root.SelectNodes(string.Format("/symbols/symbol/text[@lang='{0}']", langIdFrom)); HashSet <SymbolText> handledSymbolTexts = new HashSet <SymbolText>(); foreach (XmlNode node in allTexts) { SymbolText symText = new SymbolText(); symText.ReadFromXmlElementNode((XmlElement)node); symText.Lang = langIdTo; XmlElement parentNode = (XmlElement)node.ParentNode; string symbolId = parentNode.GetAttribute("id"); if (!handledSymbolTexts.Contains(symText)) { AddOneDescriptionText(symbolId, symText); handledSymbolTexts.Add(symText); } } }
// Add one description text. private void AddOneDescriptionText(string symbolId, SymbolText symbolText) { // Find existing symbol, for this symbolId. Could be more than one for ones that have different ones for different standards. XmlNodeList symbolNodes = root.SelectNodes(string.Format("/symbols/symbol[@id='{0}']", symbolId)); foreach (XmlNode symbolNode in symbolNodes) { // The new node to insert/replace. XmlNode newNode = symbolText.CreateXmlElement(xmldoc, "text"); // Find existing name node, for this symbolId XmlNodeList nameNodeList = symbolNode.SelectNodes("name"); XmlNode lastNameNode = nameNodeList[nameNodeList.Count - 1]; // Add new text node XmlNode parent = lastNameNode.ParentNode; parent.InsertAfter(newNode, lastNameNode); parent.InsertBefore(xmldoc.CreateTextNode("\r\n\t\t"), newNode); } }
// Update the data from the current state of the right hand side controls void UpdateDataFromControls(string id) { if (checkBoxShowKey.Enabled) customSymbolKey[id] = checkBoxShowKey.Checked; if (useAsLocalizeTool) { SymbolText symText = new SymbolText(); symText.Lang = LangId; symText.Text = textBoxSymbolName.Text; if (!symbolNames.ContainsKey(id)) symbolNames[id] = new List<SymbolText>(); List<SymbolText> list = symbolNames[id]; int index = list.FindIndex(st => (st.Lang == LangId)); if (index >= 0) list[index] = symText; else list.Add(symText); } }
public override void ReadAttributesAndContent(XmlInput xmlinput) { firstControlCode = 31; disallowInvertibleCodes = true; courseAppearance.purpleColorBlend = false; // default for existing events is false, true for new events. printArea = null; // Will be set at end if not loaded. bool first = true; while (xmlinput.FindSubElement(first, "title", "notes", "map", "all-controls", "numbering", "punch-card", "course-appearance", "print-area", "descriptions", "ocad", "custom-symbol-text")) { switch (xmlinput.Name) { case "title": title = xmlinput.GetContentString(); break; case "notes": notes = xmlinput.GetContentString(); break; case "map": mapScale = xmlinput.GetAttributeFloat("scale"); string kindString = xmlinput.GetAttributeString("kind"); switch (kindString) { case "none": mapType = MapType.None; break; case "OCAD": mapType = MapType.OCAD; break; case "bitmap": mapType = MapType.Bitmap; break; case "PDF": mapType = MapType.PDF; break; default: xmlinput.BadXml("Invalid map kind '{0}'", kindString); break; } if (mapType == MapType.Bitmap) mapDpi = xmlinput.GetAttributeFloat("dpi"); else mapDpi = 0; if (mapType == MapType.OCAD) ignoreMissingFonts = xmlinput.GetAttributeBool("ignore-missing-fonts", false); if (mapType != MapType.None) { mapFileName = xmlinput.GetContentString(); mapFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(xmlinput.FileName), mapFileName)); // file name is relative to the XML file } else { mapFileName = null; xmlinput.Skip(); } break; case "all-controls": allControlsPrintScale = xmlinput.GetAttributeFloat("print-scale", 0); allControlsDescKind = EventDBUtil.ReadDescriptionKindAttribute(xmlinput); xmlinput.Skip(); break; case "numbering": firstControlCode = xmlinput.GetAttributeInt("start", 31); disallowInvertibleCodes = xmlinput.GetAttributeBool("disallow-invertible", true); xmlinput.Skip(); break; case "punch-card": punchcardFormat.boxesDown = xmlinput.GetAttributeInt("rows", PunchcardAppearance.defaultBoxesDown); punchcardFormat.boxesAcross = xmlinput.GetAttributeInt("columns", PunchcardAppearance.defaultBoxesAcross); punchcardFormat.leftToRight = xmlinput.GetAttributeBool("left-to-right", PunchcardAppearance.defaultLeftToRight); punchcardFormat.topToBottom = xmlinput.GetAttributeBool("top-to-bottom", PunchcardAppearance.defaultTopToBottom); xmlinput.Skip(); break; case "course-appearance": courseAppearance.controlCircleSize = xmlinput.GetAttributeFloat("control-circle-size-ratio", 1.0F); courseAppearance.lineWidth = xmlinput.GetAttributeFloat("line-width-ratio", 1.0F); courseAppearance.centerDotDiameter = xmlinput.GetAttributeFloat("center-dot-diameter", 0.0F); courseAppearance.numberHeight = xmlinput.GetAttributeFloat("number-size-ratio", 1.0F); courseAppearance.numberBold = xmlinput.GetAttributeBool("number-bold", false); courseAppearance.numberOutlineWidth = xmlinput.GetAttributeFloat("number-outline-width", 0.0F); courseAppearance.autoLegGapSize = xmlinput.GetAttributeFloat("auto-leg-gap-size", 3.5F); // default value courseAppearance.purpleColorBlend = xmlinput.GetAttributeBool("blend-purple", false); courseAppearance.purpleC = xmlinput.GetAttributeFloat("purple-cyan", -1F); courseAppearance.purpleM = xmlinput.GetAttributeFloat("purple-magenta", -1F); courseAppearance.purpleY = xmlinput.GetAttributeFloat("purple-yellow", -1F); courseAppearance.purpleK = xmlinput.GetAttributeFloat("purple-black", -1F); if (courseAppearance.purpleC < 0 || courseAppearance.purpleM < 0 || courseAppearance.purpleY < 0 || courseAppearance.purpleK < 0) { courseAppearance.useDefaultPurple = true; courseAppearance.purpleC = courseAppearance.purpleM = courseAppearance.purpleY = courseAppearance.purpleK = 1; } else { courseAppearance.useDefaultPurple = false; } xmlinput.Skip(); break; case "print-area": printArea = new PrintArea(); printArea.ReadAttributesAndContent(xmlinput); break; case "descriptions": descriptionLangId = xmlinput.GetAttributeString("lang"); string descriptionColor = xmlinput.GetAttributeString("color", "black"); if (descriptionColor.Equals("purple", StringComparison.InvariantCultureIgnoreCase)) courseAppearance.descriptionsPurple = true; else courseAppearance.descriptionsPurple = false; xmlinput.Skip(); break; case "ocad": courseAppearance.useOcadOverprint = xmlinput.GetAttributeBool("overprint-colors", false); xmlinput.Skip(); break; case "custom-symbol-text": string iof2004id = xmlinput.GetAttributeString("iof-2004-ref"); bool key = xmlinput.GetAttributeBool("show-key", false); customSymbolKey[iof2004id] = key; xmlinput.Read(); xmlinput.MoveToContent(); List<SymbolText> texts = new List<SymbolText>(); if (xmlinput.Reader.NodeType == XmlNodeType.Text) { // Reading the old-style custom symbol text. string customText = xmlinput.Reader.ReadString(); if (iof2004id.StartsWith("8.", StringComparison.InvariantCulture)) customText += " {0}"; // old style for modifiers didn't have the fill-in placeholder. SymbolText text = new SymbolText(); text.Lang = "en"; text.Plural = false; text.Gender = ""; text.Text = customText; texts.Add(text); } else { // Read the new-style custom symbol text. while (xmlinput.Reader.NodeType == XmlNodeType.Element && xmlinput.Name == "text") { SymbolText text = new SymbolText(); text.ReadXml(xmlinput); texts.Add(text); xmlinput.Skip(); } } customSymbolText[iof2004id] = texts; xmlinput.Skip(); break; } first = false; } if (allControlsPrintScale == 0) allControlsPrintScale = mapScale; float scaleRatio; if (mapScale > 0 && allControlsPrintScale > 0) scaleRatio = allControlsPrintScale / mapScale; else scaleRatio = 1.0F; if (printArea == null) { printArea = MapUtil.GetDefaultPrintArea(mapFileName, scaleRatio); } }
// Read the values in the grid into symbolTexts. void ReadGrid() { List<SymbolText> symtexts = new List<SymbolText>(); foreach (DataGridViewRow row in dataGridView.Rows) { SymbolText text = new SymbolText(); text.Lang = symLanguage.LangId; text.Text = UnsanitizeFillIn((string) row.Cells[3].Value); if (genderColumn.Visible) text.Gender = (string) row.Cells[1].Value; else if (showGenderList) text.Gender = comboBoxGenderChooser.Text; else text.Gender = ""; if (numberColumn.Visible) text.Plural = (string) row.Cells[0].Value == MiscText.Plural; else text.Plural = false; if (caseColumn.Visible) { text.Case = (string)row.Cells[2].Value; } if (showCaseList) { if (comboBoxCaseChooser.SelectedIndex <= 0) text.CaseOfModified = ""; else text.CaseOfModified = (string) comboBoxCaseChooser.SelectedItem; } symtexts.Add(text); } symbolTexts = symtexts; }
// Copy all texts from one language to another. private void CopyAllTexts(string langIdFrom, string langIdTo) { XmlNodeList allTexts = root.SelectNodes(string.Format("/symbols/symbol/text[@lang='{0}']", langIdFrom)); foreach (XmlNode node in allTexts) { SymbolText symText = new SymbolText(); symText.ReadFromXmlElementNode((XmlElement) node); symText.Lang = langIdTo; AddOneDescriptionText(((XmlElement)node.ParentNode).GetAttribute("id"), symText); } }
// Add one symbol name. private void AddOneSymbolName(string symbolId, SymbolText symbolText) { symbolText.Plural = false; symbolText.Gender = ""; // The new node to insert/replace. XmlNode newNode = symbolText.CreateXmlElement(xmldoc, "name"); // Find existing symbol, for this symbolId XmlNode symbolNode = root.SelectSingleNode(string.Format("/symbols/symbol[@id='{0}']", symbolId)); // Add new name node symbolNode.PrependChild(newNode); symbolNode.InsertBefore(xmldoc.CreateTextNode("\r\n\t\t"), newNode); }
// Add one description text. private void AddOneDescriptionText(string symbolId, SymbolText symbolText) { // The new node to insert/replace. XmlNode newNode = symbolText.CreateXmlElement(xmldoc, "text"); // Find existing name node, for this symbolId XmlNodeList nameNodeList = root.SelectNodes(string.Format("/symbols/symbol[@id='{0}']/name", symbolId)); XmlNode lastNameNode = nameNodeList[nameNodeList.Count - 1]; // Add new text node XmlNode parent = lastNameNode.ParentNode; parent.InsertAfter(newNode, lastNameNode); parent.InsertBefore(xmldoc.CreateTextNode("\r\n\t\t"), newNode); }
/// <summary> /// Read the state of this symbol from XML. The xmlinput must be on a /// symbol node. /// </summary> public void ReadXml(XmlInput xmlinput) { xmlinput.CheckElement("symbol"); this.kind = xmlinput.GetAttributeString("kind")[0]; this.id = xmlinput.GetAttributeString("id"); this.sizeIsDepth = xmlinput.GetAttributeBool("size-is-depth", false); bool first = true; List<SymbolStroke> strokes = new List<SymbolStroke>(); while (xmlinput.FindSubElement(first, new string[] { "name", "text", "filled-circle", "circle", "polygon", "filled-polygon", "lines", "beziers", "filled-beziers" })) { SymbolStroke stroke = new SymbolStroke(); bool isStroke = true; switch (xmlinput.Name) { case "name": xmlinput.CheckElement("name"); string language = xmlinput.GetAttributeString("lang"); name.Add(language, xmlinput.GetContentString()); isStroke = false; break; case "text": xmlinput.CheckElement("text"); SymbolText symtext = new SymbolText(); symtext.ReadXml(xmlinput); texts.Add(symtext); isStroke = false; break; case "filled-circle": xmlinput.CheckElement("filled-circle"); stroke.kind = SymbolStrokes.Disc; stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "circle": xmlinput.CheckElement("circle"); stroke.kind = SymbolStrokes.Circle; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "polygon": xmlinput.CheckElement("polygon"); stroke.kind = SymbolStrokes.Polygon; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "filled-polygon": xmlinput.CheckElement("filled-polygon"); stroke.kind = SymbolStrokes.FilledPolygon; break; case "lines": xmlinput.CheckElement("lines"); stroke.kind = SymbolStrokes.Polyline; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "beziers": xmlinput.CheckElement("beziers"); stroke.kind = SymbolStrokes.PolyBezier; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); break; case "filled-beziers": xmlinput.CheckElement("filled-beziers"); stroke.kind = SymbolStrokes.FilledPolyBezier; break; } if (isStroke) { stroke.points = ReadPoints(xmlinput); strokes.Add(stroke); } first = false; } if (this.name == null) xmlinput.BadXml("Missing name element"); if (texts.Count == 0) xmlinput.BadXml("Missing text element"); this.strokes = strokes.ToArray(); }
/// <summary> /// Read the state of this symbol from XML. The xmlinput must be on a /// symbol node. /// </summary> public void ReadXml(XmlInput xmlinput) { xmlinput.CheckElement("symbol"); this.kind = xmlinput.GetAttributeString("kind")[0]; this.id = xmlinput.GetAttributeString("id"); this.replacementId = xmlinput.GetAttributeString("replacement-id", null); this.sizeIsDepth = xmlinput.GetAttributeBool("size-is-depth", false); string standardStrings = xmlinput.GetAttributeString("standard", ""); if (standardStrings != "") { this.standards = standardStrings.Split(','); } bool first = true; List <SymbolStroke> strokes = new List <SymbolStroke>(); while (xmlinput.FindSubElement(first, new string[] { "name", "text", "filled-circle", "circle", "polygon", "filled-polygon", "lines", "beziers", "filled-beziers" })) { SymbolStroke stroke = new SymbolStroke(); bool isStroke = true; switch (xmlinput.Name) { case "name": xmlinput.CheckElement("name"); string language = xmlinput.GetAttributeString("lang"); name.Add(language, xmlinput.GetContentString()); isStroke = false; break; case "text": xmlinput.CheckElement("text"); SymbolText symtext = new SymbolText(); symtext.ReadXml(xmlinput); texts.Add(symtext); isStroke = false; break; case "filled-circle": xmlinput.CheckElement("filled-circle"); stroke.kind = SymbolStrokes.Disc; stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "circle": xmlinput.CheckElement("circle"); stroke.kind = SymbolStrokes.Circle; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.radius = xmlinput.GetAttributeFloat("radius"); break; case "polygon": xmlinput.CheckElement("polygon"); stroke.kind = SymbolStrokes.Polygon; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "filled-polygon": xmlinput.CheckElement("filled-polygon"); stroke.kind = SymbolStrokes.FilledPolygon; break; case "lines": xmlinput.CheckElement("lines"); stroke.kind = SymbolStrokes.Polyline; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); stroke.corners = ToLineJoin(xmlinput.GetAttributeString("corners", "round"), xmlinput); break; case "beziers": xmlinput.CheckElement("beziers"); stroke.kind = SymbolStrokes.PolyBezier; stroke.thickness = xmlinput.GetAttributeFloat("thickness"); stroke.ends = ToLineCap(xmlinput.GetAttributeString("ends", "round"), xmlinput); break; case "filled-beziers": xmlinput.CheckElement("filled-beziers"); stroke.kind = SymbolStrokes.FilledPolyBezier; break; } if (isStroke) { stroke.points = ReadPoints(xmlinput); strokes.Add(stroke); } first = false; } if (this.name == null) { xmlinput.BadXml("Missing name element"); } if (texts.Count == 0) { xmlinput.BadXml("Missing text element"); } this.strokes = strokes.ToArray(); }