public SVGPath(SVGPath path) { _ID = path._ID; _cg = path._cg.Transform(Matrix3x2.Identity); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
private SVGPath XNodeToSVGPath(XNode node) { SVGPath sp = null; XElement element = null; XAttribute attribute = null; string id = null; string path = null; try { if (node is XElement) { element = (XElement)node; if (element.HasAttributes) { IEnumerator <XAttribute> itr = null;// = xml.DescendantNodes().GetEnumerator(); itr = element.Attributes().GetEnumerator(); while (itr.MoveNext()) { attribute = itr.Current; if (attribute.Name == "unicode") { id = attribute.Value;//get element value } if (attribute.Name == "d") { path = attribute.Value; } } if (id != null && path != null) { sp = new SVGPath(id, path); } } } else { return(null); } } catch (System.Xml.XmlException xe) { Debug.WriteLine(xe.Message); Debug.WriteLine(xe.StackTrace); } catch (Exception exc) { Debug.WriteLine(exc.Message); Debug.WriteLine(exc.StackTrace); } return(sp); }
private void populateLookup(XDocument xml) { IEnumerable <XElement> elements = null; try { //svg/def/font if (xml.Root.HasElements) { //elements = xml.Root.Descendants("{http://www.w3.org/2000/svg}glyph"); // if(elements == null) //elements = xml.Root.Descendants("glyph"); elements = xml.Root.Elements(); IEnumerator <XElement> itr = null; itr = elements.GetEnumerator(); elements.Count(); int ec = elements.Count(); XElement child = null; int count = 0; while (itr.MoveNext()) { child = itr.Current; SVGPath temp = XNodeToSVGPath(child); if ((temp != null) && _UnitDefinitions.ContainsKey(temp.getID()) == false)//temp will be null if node is an XCOMMENT { int tempID = Convert.ToInt32(temp.getID()); if (tempID < 63000) { tempID = tempID - 57000; } else { tempID = tempID - 54000; } //if(tempID < ) _UnitDefinitions[tempID] = temp; } //Debug.WriteLine("ID: " + temp.getID().ToString()); count++; } //end while Debug.WriteLine("# of glyphs: " + Convert.ToString(count)); } //end if } catch (Exception exc) { ErrorLogger.LogException("UnitDefTableSVG", "populateLookup", exc); } }//end populate lookup
/** * @name getSymbolDef * * @desc Returns a SymbolDef from the SymbolDefTable that matches the passed in Symbol Id * * @param index String representation of the index number * @return SVGPath */ public SVGPath getSVGPath(int index) { SVGPath returnVal = null; try { if (_TGDefinitions.ContainsKey(index)) { returnVal = new SVGPath(_TGDefinitions[index]); } } catch (Exception exc) { Debug.WriteLine(exc.Message); Debug.WriteLine(exc.StackTrace); } return(returnVal); }
public static ImageInfo getIcon(String symbolID, int size, Color color, int outlineSize) { ImageInfo returnVal = null; if (_tgl == null) { _tgl = TacticalGraphicLookup.getInstance(); } int mapping = _tgl.getCharCodeFromSymbol(symbolID); CanvasRenderTarget coreBMP = null; SVGPath svgTG = null; //SVGPath svgFrame = null; if (mapping > 0) { svgTG = TGSVGTable.getInstance().getSVGPath(mapping); } //float scale = 1; Matrix3x2 mScale, mTranslate; Matrix3x2 mIdentity = Matrix3x2.Identity; Rect rectF = new Rect(); Matrix3x2 m = svgTG.CreateMatrix(size, size, out rectF, out mScale, out mTranslate); //svgTG.TransformToFitDimensions(size, size); Rect rr = svgTG.computeBounds(m); CanvasDevice device = CanvasDevice.GetSharedDevice(); //CanvasRenderTarget offscreen = new CanvasRenderTarget(device, width, height, 96); coreBMP = new CanvasRenderTarget(device, (int)(rr.Width + 0.5), (int)(rr.Height + 0.5), 96); using (CanvasDrawingSession cds = coreBMP.CreateDrawingSession()) { svgTG.Draw(cds, Colors.Transparent, 0, color, m); cds.DrawRectangle(coreBMP.GetBounds(device), Colors.Red); } returnVal = new ImageInfo(coreBMP, new Point(coreBMP.Size.Width / 2f, coreBMP.Size.Height / 2.0f), new Rect(0, 0, coreBMP.Size.Width, coreBMP.Size.Height), coreBMP.GetBounds(device)); return(returnVal); }
/// <summary> /// /// </summary> /// <param name="symbolID"></param> /// <param name="modifiers"></param> /// <param name="attributes"></param> /// <returns></returns> public ImageInfo RenderUnit(String symbolID, Dictionary <int, String> modifiers, Dictionary <int, String> attributes, CanvasDevice device) { //L 1.5 = 2650 pixel units in the svg font file double L1_5 = 2650; CanvasRenderTarget finalBMP = null; CanvasRenderTarget coreBMP = null; try { //get font character indexes int fillIndex = -1; int frameIndex = -1; int symbol1Index = -1; int symbol2Index = -1; SVGPath svgFill = null; SVGPath svgFrame = null; SVGPath svgSymbol1 = null; SVGPath svgSymbol2 = null; //get attributes int alpha = 255; Boolean drawAsIcon = false; Boolean keepUnitRatio = true; int pixelSize = 0; Color fillColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getFillColorOfAffiliation(symbolID)); Color frameColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getLineColorOfAffiliation(symbolID)); if (attributes == null) { attributes = new Dictionary <int, string>(); } if (attributes.ContainsKey(MilStdAttributes.LineColor)) { frameColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getColorFromHexString(attributes[MilStdAttributes.LineColor])); } if (attributes.ContainsKey(MilStdAttributes.FillColor)) { fillColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getColorFromHexString(attributes[MilStdAttributes.FillColor])); } if (attributes.ContainsKey(MilStdAttributes.Alpha)) { alpha = Convert.ToInt32(attributes[MilStdAttributes.Alpha]); } if (attributes.ContainsKey(MilStdAttributes.DrawAsIcon)) { drawAsIcon = Convert.ToBoolean(attributes[MilStdAttributes.DrawAsIcon]); } if (attributes.ContainsKey(MilStdAttributes.PixelSize)) { pixelSize = Convert.ToInt32(attributes[MilStdAttributes.PixelSize]); } else { pixelSize = 35; } if (attributes.ContainsKey(MilStdAttributes.KeepUnitRatio)) { keepUnitRatio = Convert.ToBoolean(attributes[MilStdAttributes.KeepUnitRatio]); } String basicID = SymbolUtilities.getBasicSymbolIDStrict(symbolID); UnitFontLookupInfo ufli = UnitFontLookup.getInstance().getLookupInfo(basicID); fillIndex = UnitFontLookup.getFillCode(symbolID); frameIndex = UnitFontLookup.getFrameCode(symbolID, fillIndex); if (ufli != null) { symbol1Index = ufli.getMapping1(symbolID); symbol2Index = ufli.getMapping2(); } if (fillIndex > 0) { svgFill = UnitSVGTable.getInstance().getSVGPath(fillIndex); } if (frameIndex > 0) { svgFrame = UnitSVGTable.getInstance().getSVGPath(frameIndex); } if (symbol1Index > 0) { svgSymbol1 = UnitSVGTable.getInstance().getSVGPath(symbol1Index); } if (symbol2Index > 0) { svgSymbol2 = UnitSVGTable.getInstance().getSVGPath(symbol2Index); } //get dimensions for this symbol given the font size & fill index Matrix3x2 matrix = new Matrix3x2(); double heightL = 1; double widthL = 1; Rect rectFrame = svgFrame.getBounds(); if (keepUnitRatio) { double ratio = pixelSize / L1_5 / 1.5; widthL = UnitFontLookup.getUnitRatioWidth(fillIndex); heightL = UnitFontLookup.getUnitRatioHeight(fillIndex); if (widthL > heightL) { ratio = ratio * widthL; } else { ratio = ratio * heightL; } pixelSize = (int)((ratio * L1_5) + 0.5); } Matrix3x2 mScale, mTranslate; Matrix3x2 mIdentity = Matrix3x2.Identity; Rect rectF = new Rect(); matrix = svgFrame.CreateMatrix(pixelSize, pixelSize, out rectF, out mScale, out mTranslate); //int w = (int)(rectF.Width + 1.5f); //int h = (int)(rectF.Height + 1.5f); int w = (int)(rectF.Width); int h = (int)(rectF.Height); if (w == pixelSize && h != pixelSize) { h = (int)Math.Ceiling(rectF.Height); } else if (h == pixelSize && w != pixelSize) { w = (int)Math.Ceiling(rectF.Width); } bool bufferUsed = false; if (w < coreBufferSize && h < coreBufferSize) { if (coreUnitBuffer == null) { if (device == null) { device = CanvasDevice.GetSharedDevice(); } coreUnitBuffer = new CanvasRenderTarget(device, coreBufferSize, coreBufferSize, 96);//new Bitmap(w, h); } coreBMP = coreUnitBuffer; bufferUsed = true; } else { if (device == null) { device = CanvasDevice.GetSharedDevice(); } coreBMP = new CanvasRenderTarget(device, w, h, 96);//new Bitmap(w, h); } Point centerPoint = new Point(w / 2, h / 2); //get & setup graphics object for destination BMP using (CanvasDrawingSession ds = coreBMP.CreateDrawingSession()) { ds.Clear(Colors.Transparent); //clear canvas //ds.Transform = matrix; // ds.Transform = mScale; //draw symbol to BMP // ds.Transform = mScale * mTranslate; if (svgFill != null) { //svgFill.Transform(mScale); //svgFill.Transform(mTranslate); svgFill.Draw(ds, Colors.Transparent, 0, fillColor, matrix); } if (svgFrame != null) { svgFrame.Draw(ds, Colors.Transparent, 0, frameColor, matrix); } if (svgSymbol2 != null) { //svgSymbol2.Transform(mScale); //svgSymbol2.Transform(mTranslate); svgSymbol2.Draw(ds, Colors.Transparent, 0, RenderUtilities.DrawingColorToUIColor(ufli.getColor2()), matrix); } if (svgSymbol1 != null) { //svgSymbol1.Transform(mScale); //svgSymbol1.Transform(mTranslate); svgSymbol1.Draw(ds, Colors.Transparent, 0, RenderUtilities.DrawingColorToUIColor(ufli.getColor1()), matrix); } //ds.Transform = Matrix3x2.Identity; }//*/ /* * if (svgFill != null) * { * svgFill.Transform(mScale); * svgFill.Transform(mTranslate); * //svgFill.Transform(matrix); * svgFill.Draw(coreBMP, Colors.Transparent, 0, fillColor, mIdentity); * } * if (svgFrame != null) * { * svgFrame.Draw(coreBMP, Colors.Transparent, 0, frameColor, mIdentity); * } * if (svgSymbol2 != null) * { * svgSymbol2.Transform(mScale); * svgSymbol2.Transform(mTranslate); * svgSymbol2.Draw(coreBMP, Colors.Transparent, 0, ufli.getColor2(), mIdentity); * } * if (svgSymbol1 != null) * { * svgSymbol1.Transform(mScale); * svgSymbol1.Transform(mTranslate); * svgSymbol1.Draw(coreBMP, Colors.Transparent, 0, ufli.getColor1(), mIdentity); * }//*/ Rect coreDimensions = new Rect(0, 0, w, h); Rect finalDimensions = new Rect(0, 0, w, h); //adjust centerpoint for HQStaff if present if (SymbolUtilities.isHQ(symbolID)) { Point point1 = new Point(); Point point2 = new Point(); string affiliation = symbolID.Substring(1, 2); if (affiliation == ("F") || affiliation == ("A") || affiliation == ("D") || affiliation == ("M") || affiliation == ("J") || affiliation == ("K") || affiliation == ("N") || affiliation == ("L")) { point1.X = 0; point1.Y = (coreBMP.Size.Height); point2.X = point1.X; point2.Y = point1.Y + coreBMP.Size.Height; } else { point1.X = 1; point1.Y = (coreBMP.Size.Height / 2); point2.X = point1.X; point2.Y = point1.Y + coreBMP.Size.Height; } centerPoint = point2; } if (device == null) { device = CanvasDevice.GetSharedDevice(); } finalBMP = new CanvasRenderTarget(device, (float)finalDimensions.Width, (float)finalDimensions.Height, 96); ImageInfo ii = new ImageInfo(coreBMP, new Point(centerPoint.X, centerPoint.Y), new Rect(0, 0, coreBMP.Size.Width, coreBMP.Size.Height), coreBMP.GetBounds(device)); //process display modifiers ImageInfo iinew = null; Boolean hasDisplayModifiers = ModifierRenderer.hasDisplayModifiers(symbolID, modifiers); Boolean hasTextModifiers = ModifierRenderer.hasTextModifiers(symbolID, modifiers, attributes); if (hasDisplayModifiers) { iinew = ModifierRenderer.ProcessUnitDisplayModifiers(symbolID, ii, modifiers, attributes, true, device); }//*/ if (iinew != null) { ii = iinew; } iinew = null; //process text modifiers if (hasTextModifiers) { //iinew = ModifierRenderer.ProcessUnitTextModifiers(ii, symbolID, modifiers, attributes); }//*/ if (iinew != null) { ii = iinew; } iinew = null; ////// svgFill = null; svgFrame = null; svgSymbol1 = null; svgSymbol2 = null; device = null; //if(bufferUsed==false) // coreBMP.Dispose(); coreBMP = null; finalBMP = null; return(ii); } catch (Exception exc) { ErrorLogger.LogException("SinglePointRenderer", "RenderUnit", exc); return(null); } }
public ImageInfo RenderSPTG(String symbolID, Dictionary <int, String> modifiers, Dictionary <int, String> attributes) { if (modifiers == null) { modifiers = new Dictionary <int, string>(); } if (attributes == null) { attributes = new Dictionary <int, string>(); } CanvasRenderTarget finalBmp = null; CanvasRenderTarget coreBMP = null; try { //get font character indexes (svg file for this renderer port) int fillIndex = -1; int frameIndex = -1; int alpha = 255; int symbolOutlineSize = 0; Color symbolOutlineColor = Colors.Transparent; Boolean drawAsIcon = false; Boolean keepUnitRatio = true; int pixelSize = 35; int w = pixelSize; int h = pixelSize; char[] fillString = new char[1]; char[] frameString = new char[1]; char[] symbol1 = new char[1]; char[] symbol2 = new char[1]; //_spFontSize; Color lineColor = Colors.Transparent; Color fillColor = Colors.Transparent; if (attributes.ContainsKey(MilStdAttributes.LineColor)) { lineColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getColorFromHexString(attributes[MilStdAttributes.LineColor])); } else { lineColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getLineColorOfAffiliation(symbolID)); } if (attributes.ContainsKey(MilStdAttributes.FillColor)) { fillColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getColorFromHexString(attributes[MilStdAttributes.FillColor])); } if (attributes.ContainsKey(MilStdAttributes.Alpha)) { alpha = Convert.ToInt32(attributes[MilStdAttributes.Alpha]); } if (attributes.ContainsKey(MilStdAttributes.SymbolOutlineColor)) { symbolOutlineColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getColorFromHexString(attributes[MilStdAttributes.SymbolOutlineColor])); } else { symbolOutlineColor = RenderUtilities.getIdealTextBackgroundColor(lineColor); } if (attributes.ContainsKey(MilStdAttributes.SymbolOutlineSize)) { symbolOutlineSize = Convert.ToInt32(attributes[MilStdAttributes.SymbolOutlineSize]); } else { symbolOutlineSize = RendererSettings.getInstance().getSymbolOutlineWidth(); } if (symbolOutlineSize <= 0) { symbolOutlineColor = Colors.Transparent; } if (attributes.ContainsKey(MilStdAttributes.DrawAsIcon)) { drawAsIcon = Convert.ToBoolean(attributes[MilStdAttributes.DrawAsIcon]); } if (attributes.ContainsKey(MilStdAttributes.PixelSize)) { pixelSize = Convert.ToInt32(attributes[MilStdAttributes.PixelSize]); } if (attributes.ContainsKey(MilStdAttributes.KeepUnitRatio)) { keepUnitRatio = Convert.ToBoolean(attributes[MilStdAttributes.KeepUnitRatio]); } SinglePointLookupInfo spli = SinglePointLookup.getInstance().getSPLookupInfo(SymbolUtilities.getBasicSymbolIDStrict(symbolID)); if (spli == null)//default to action point on bad symbolID { if (modifiers == null) { modifiers = new Dictionary <int, string>(); } if (modifiers.ContainsKey(ModifiersTG.H_ADDITIONAL_INFO_1)) { modifiers[ModifiersTG.H1_ADDITIONAL_INFO_2] = modifiers[ModifiersTG.H_ADDITIONAL_INFO_1]; } modifiers[ModifiersTG.H_ADDITIONAL_INFO_1] = symbolID.Substring(0, 10); symbolID = "G" + SymbolUtilities.getAffiliation(symbolID) + "G" + SymbolUtilities.getStatus(symbolID) + "GPP---****X"; spli = SinglePointLookup.getInstance().getSPLookupInfo(symbolID); lineColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getLineColorOfAffiliation(symbolID)); //fillColor = SymbolUtilities.getFillColorOfAffiliation(symbolID); } //Check if we need to set 'N' to ENY if (symbolID[1] == 'H' && drawAsIcon == false) { if (modifiers == null) { modifiers = new Dictionary <int, string>(); } modifiers[ModifiersTG.N_HOSTILE] = "ENY"; } if (SymbolUtilities.getStatus(symbolID) == "A") { frameIndex = spli.getMappingA(); } else { frameIndex = spli.getMappingP(); } if (SymbolUtilities.isTGSPWithFill(symbolID)) { String fillID = SymbolUtilities.getTGFillSymbolCode(symbolID); if (fillID != null) { fillIndex = SinglePointLookup.getInstance().getCharCodeFromFillID(fillID); } } else if (SymbolUtilities.isWeatherSPWithFill(symbolID)) { fillIndex = frameIndex + 1; fillColor = RenderUtilities.DrawingColorToUIColor(SymbolUtilities.getFillColorOfWeather(symbolID)); } fillString[0] = (char)fillIndex; frameString[0] = (char)frameIndex; SVGPath svgFill = null; SVGPath svgFrame = null; if (fillIndex > 0) { svgFill = SymbolSVGTable.getInstance().getSVGPath(fillIndex); } if (frameIndex > 0) { svgFrame = SymbolSVGTable.getInstance().getSVGPath(frameIndex); } float scale = 1; Rect rr = svgFrame.getBounds(); if (keepUnitRatio) { //scale = pixelSize * .00095f;// 1f; scale = pixelSize / 34f;//height of friendly unit before scaling. if (rr.Height > rr.Width) { pixelSize = (int)((scale * rr.Height) + 0.5); } else { pixelSize = (int)((scale * rr.Width) + 0.5); } } Matrix3x2 mScale, mTranslate; Matrix3x2 mIdentity = Matrix3x2.Identity; Rect rectF = new Rect(); Matrix3x2 m = svgFrame.CreateMatrix(pixelSize, pixelSize, out rectF, out mScale, out mTranslate); //Matrix3x2 m = svgFrame.TransformToFitDimensions(pixelSize, pixelSize); rr = svgFrame.computeBounds(m); w = (int)((rr.Width) + 0.5f); h = (int)((rr.Height) + 0.5f); //draw location System.Drawing.RectangleF sdrr = new System.Drawing.RectangleF((float)rr.X, (float)rr.Y, (float)rr.Width, (float)rr.Height); System.Drawing.PointF sdpf = SymbolDimensions.getSymbolCenter(spli.getBasicSymbolID(), sdrr); Point centerPoint = new Point(sdpf.X, sdpf.Y); Point location = new Point(0, 0); location.X = centerPoint.X; location.Y = 0;// centerPoint.Y; //location.Y = (h * 1.5f); float outlineOffsetX = 0; float outlineOffsetY = 0; Matrix3x2 mOutline = new Matrix3x2(); CanvasDevice device = CanvasDevice.GetSharedDevice(); //CanvasRenderTarget offscreen = new CanvasRenderTarget(device, width, height, 96); if (symbolOutlineSize > 0) { Rect rectOutline = ShapeUtilities.inflate(rr, symbolOutlineSize, symbolOutlineSize); // svgFrame.getBounds(symbolOutlineSize); outlineOffsetX = (float)((rectOutline.Width - w) / 2f); outlineOffsetY = (float)((rectOutline.Height - h) / 2f); //too much added for AA w = (int)(rectOutline.Width + 0.5f); h = (int)(rectOutline.Height + 0.5f); mOutline = Matrix3x2.CreateTranslation(outlineOffsetX, outlineOffsetY); centerPoint.X += outlineOffsetX; centerPoint.Y += outlineOffsetY; coreBMP = new CanvasRenderTarget(device, w, h, 96);// new Bitmap(w, h);//getBounds adds too much for AA } else { coreBMP = new CanvasRenderTarget(device, w, h, 96);//add for AA } //coreBMP = new Bitmap(w, h); //draw test outline //g.DrawRectangle(new Pen(Color.LightSkyBlue), 0, 0, coreBMP.Width - 1, coreBMP.Height - 1); using (CanvasDrawingSession cds = coreBMP.CreateDrawingSession()) { if (svgFill != null) { svgFill.Transform(m); svgFill.Draw(cds, Colors.Transparent, 0, fillColor, mOutline); } if (svgFrame != null) { svgFrame.Transform(m); svgFrame.Draw(cds, symbolOutlineColor, symbolOutlineSize, lineColor, mOutline); } cds.DrawRectangle(new Rect(0, 0, (int)(coreBMP.Size.Width + 0.5f), (int)(coreBMP.Size.Height + 0.5f)), Colors.Red); } Rect coreDimensions = new Rect(0, 0, (int)(coreBMP.Size.Width + 0.5f), (int)(coreBMP.Size.Height + 0.5f)); ImageInfo ii = new ImageInfo(coreBMP, centerPoint, coreDimensions, coreBMP.GetBounds(device)); //process display modifiers Boolean hasDisplayModifiers = ModifierRenderer.hasDisplayModifiers(symbolID, modifiers); Boolean hasTextModifiers = ModifierRenderer.hasTextModifiers(symbolID, modifiers, attributes); ImageInfo iinew = null; if (hasDisplayModifiers) { //iinew = ModifierRenderer.ProcessUnitDisplayModifiers(symbolID, ii, modifiers, attributes, true, device); }//*/ if (iinew != null) { ii = iinew; } iinew = null; //process text modifiers /*if (hasTextModifiers) * { * //iinew = ModifierRenderer.ProcessUnitTextModifiers(symbolID, ii, modifiers, attributes); * iinew = ModifierRenderer.ProcessUnitTextModifiers(ii, symbolID, modifiers, attributes); * }//*/ if (iinew != null) { ii = iinew; } iinew = null; /*if (coreBMP != null) * { * coreBMP.Dispose(); * coreBMP = null; * }//*/ return(ii); } catch (Exception exc) { ErrorLogger.LogException("SinglePointRenderer", "RenderSPTG", exc); return(null); } }