Exemplo n.º 1
0
        private void Init()
        {
            //@"(?<=[M,m])"
            StringBuilder sb = new StringBuilder();

            sb.Append(@"(?=[");
            for (int i = 0; i < svgCommands.Length; i++)
            {
                sb.Append(svgCommands[i]);
                if (i < (svgCommands.Length - 1))
                {
                    sb.Append(',');
                }
            }
            sb.Append("])");
            _regex = sb.ToString();//@"(?=[" + sb.ToString() + "])";

            SymbolSVGTable st = SymbolSVGTable.getInstance();
            UnitSVGTable   ut = UnitSVGTable.getInstance();
        }
Exemplo n.º 2
0
        private void Init()
        {
            try
            {
                Debug.Write("MilStdIconRenderer.Init()");
                Stopwatch sw = new Stopwatch();
                sw.Start();
                SymbolDefTable.getInstance();
                Debug.Write("SymbolDefTable Loaded");
                SinglePointLookup.getInstance();
                Debug.Write("SinglePointLookup Loaded");
                SymbolSVGTable.getInstance();
                Debug.Write("SymbolSVGTable Loaded");


                UnitDefTable.getInstance();
                Debug.Write("UnitDefTable Loaded");
                UnitFontLookup.getInstance();
                Debug.Write("UnitFontLookup Loaded");
                UnitSVGTable.getInstance();
                Debug.Write("UnitSVGTable Loaded");

                TacticalGraphicLookup.getInstance();
                Debug.Write("TacticalGraphicLookup Loaded");
                TGSVGTable.getInstance();
                Debug.Write("TGSVGTable Loaded");//*/
                sw.Stop();
                string ExecutionTimeTaken = string.Format("Minutes :{0} Seconds :{1} Mili seconds :{2}", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);
                Debug.WriteLine("Init Time: " + ExecutionTimeTaken);
            }
            catch (InvalidOperationException ioe)
            {
                Debug.Write(ioe.Message);
                Debug.Write(ioe.StackTrace);
            }
            catch (Exception exc)
            {
                Debug.Write(exc.Message);
                Debug.Write(exc.StackTrace);
            }
        }
        /// <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);
            }
        }