コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // ascii printable range
            counter = 0;
            byte start = 0x20;
            byte end   = 0x7e;
            int  range = end - start;

            progressBar1.Maximum = range;
            progressBar1.Step    = 1;
            progressBar1.Value   = progressBar1.Minimum;

            fontSaveFile.Filter = "PNG file (*.png)|*.png|All files (*.*)|*.*";
            if (fontSaveFile.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var fnt =
                (from font in System.Drawing.FontFamily.Families
                 where font.Name == fontList.SelectedItem.ToString()
                 select font).First();

            Font f = FindFontWithDimensions(fnt, 256, 256, 16);

            for (byte i = start; i <= end; i++)
            {
                char c = SignedDistanceFieldRenderer.AsciiToChar(i);

                ThreadPool.QueueUserWorkItem(
                    new WaitCallback(RenderDistanceFieldForAsciiChar),
                    new FontState(f, c, GetInterpolationMode(), range, fontSaveFile.FileName)
                    );
            }
        }
コード例 #2
0
        private void DrawDistanceResults(object obj)
        {
            int w = 512;
            int h = 256;

            FontState state = (FontState)obj;
            Bitmap    bmp;

            lock (dict)
            {
                bmp = SignedDistanceFieldRenderer.CreateTextureAtlasFromCachedBitmaps(dict, w, h);
            }

            bmp.Save(state.filename, ImageFormat.Png);
            state.s.Stop();

            fontPreview.Invoke((MethodInvoker) delegate
            {
                fontPreview.Image = new Bitmap(bmp);
            });

            statusStrip1.Invoke((MethodInvoker) delegate
            {
                toolStripStatusLabel1.Text = string.Format("Ran for {0} seconds", state.s.ElapsedMilliseconds / 1000.0);
            });
        }
コード例 #3
0
        private void ButtonLoad_onClick(object sender, EventArgs e)//load button
        {
            //Todo: Add ability to load image file formats also
            //OpenFileDialogue.Filter = "SVG Files (*.svg)|*.svg|Image files (*.png, *.tiff, *.tif)|*.png;.tiff;.tif|All files (*.*)|*.*";
            //This may be a significant undertaking
            //Most of these routines are built with an SVG being assumed.

            OpenFileDialogue.Filter = "SVG Files (*.svg)|*.svg|All files (*.*)|*.*";
            if (OpenFileDialogue.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            lastSourceFilename = OpenFileDialogue.FileName;


            //to minimize disk IO this is only opened once here and when it needs to be rerendered for actual field generation.
            SvgDocument d = SvgDocument.Open(OpenFileDialogue.FileName);

            lastWidthHeight             = new Tuple <float, float>(d.Width.Value, d.Height.Value);
            DecalLoaded                 = true;
            this.GenerateButton.Enabled = true;
            SourceAspect                = lastWidthHeight.Item1 / lastWidthHeight.Item2;
            int sourceHeight = 4096;
            int sourceWidth  = (int)(4096 * (1.0f / SourceAspect));

            //rendered once to memory. That file in memory is downsampled for the preview image as the window is resized.
            SourceBitmap       = SignedDistanceFieldRenderer.RenderSvgToBitmapWithMaximumSize(lastSourceFilename, sourceWidth, sourceHeight);
            decalPreview.Image = BitmapHelper.ResizeBitmapToFit(SourceBitmap, decalPreview.Width, decalPreview.Height, SourceAspect);
        }
コード例 #4
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(lastSvgFilename))
     {
         svgSaveFile.Filter = "PNG Files (*.png)|*.png|All files (*.*)|*.*";
         if (svgSaveFile.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         SignedDistanceFieldRenderer.RenderSvgToDistanceFieldToFile(lastSvgFilename, svgSaveFile.FileName);
     }
 }
コード例 #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            svgOpenFile.Filter = "SVG Files (*.svg)|*.svg|All files (*.*)|*.*";
            if (svgOpenFile.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            lastSvgFilename    = svgOpenFile.FileName;
            decalPreview.Image = SignedDistanceFieldRenderer.RenderSvgToBitmapWithMaximumSize(
                svgOpenFile.FileName, decalPreview.Width, decalPreview.Height);
        }
コード例 #6
0
        //TODO: put this in the renderer class where it fits better. Will need to convert lastWidthHeight to a variable passed in.
        private Bitmap RenderSVGToFit(string FileName, int width, int height)
        {
            float documentAspect = lastWidthHeight.Item1 / lastWidthHeight.Item2;
            int   renderheight, renderwidth;

            if ((documentAspect <= 1.0f))
            {
                renderheight = height;
                renderwidth  = (int)(height * documentAspect);
            }
            else
            {
                renderheight = (int)(width * (1.0f / documentAspect));
                renderwidth  = width;
            }

            return(SignedDistanceFieldRenderer.RenderSvgToBitmapWithMaximumSize(FileName, renderwidth, renderheight));
        }
コード例 #7
0
        private void RenderDistanceFieldForAsciiChar(object obj)
        {
            FontState state = (FontState)obj;

            Bitmap bmp = SignedDistanceFieldRenderer.RenderDistanceFieldForChar(
                state.glyph, state.font, 256, 256, state.interpolation);

            lock (dict)
            {
                dict[state.glyph] = bmp;
            }

            statusStrip1.Invoke((MethodInvoker) delegate
            {
                progressBar1.PerformStep();
            });

            if (Interlocked.Increment(ref counter) > state.range)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(DrawDistanceResults), obj);
            }
        }
コード例 #8
0
        private void GenerateButton_onClick(object sender, EventArgs e)//generate button
        {
            progressBar1.Maximum = 100;
            progressBar1.Step    = 1;
            progressBar1.Value   = progressBar1.Minimum;

            if (!string.IsNullOrEmpty(lastSourceFilename))
            {
                //reWork this so that the source image is rendered as some multiple of the target image size.

                //change scale factor to a tuple to indicate x and y sizing.
                Thread gThread, iThread;
                int    scalefactor  = this.SizeSelectBox_X.SelectedIndex;
                int    scaleFactorH = this.SizeSelectBox_Y.SelectedIndex;
                int    spreadFactor = (int)this.SpreadSelector.Value;
                float  aspect       = lastWidthHeight.Item1 / lastWidthHeight.Item2;
                //separate render thread. This is the real time sink for this routime.
                gThread = new Thread(() =>
                {
                    Debug.Print("Generating distance field from " + lastSourceFilename.ToString());
                    lastGenerated      = SignedDistanceFieldRenderer.RenderSvgToDistanceFieldToBMP(lastSourceFilename, scalefactor, spreadFactor, (int)(4096 * aspect), 4096);
                    decalPreview.Image = lastGenerated;
                    Debug.Print("Distance field generated.");
                    Rendered = true;
                });
                gThread.Start();

                //thread that shows the spinning "working" graphic. while rendering in progress. Hides it when render completes.
                iThread = new Thread(() =>
                {
                    waitGraphicEnable(true);
                    gThread.Join();
                    waitGraphicEnable(false);
                });
                iThread.Start();
            }
        }