Пример #1
0
        public bool Run(IWindowFrameBackend parent)
        {
            if (!String.IsNullOrEmpty(Title))
            {
                dlg.Title = Title;
            }
            else
            {
                dlg.Title = defaultTitle;
            }

            if (!String.IsNullOrEmpty(PreviewText))
            {
                dlg.PreviewText = PreviewText;
            }
            else
            {
                dlg.PreviewText = defaultPreviewText;
            }

            if (SelectedFont != null)
            {
                dlg.SetFontName(SelectedFont.ToString());
            }

            var p      = (WindowFrameBackend)parent;
            int result = MessageService.RunCustomDialog(dlg, p != null ? p.Window : null);

            if (result == (int)Gtk.ResponseType.Ok)
            {
                SelectedFont = Font.FromName(dlg.FontName);
                return(true);
            }
            return(false);
        }
Пример #2
0
        private void OpslaanWenskaart()
        {
            try
            {
                SaveFileDialog dlg = new SaveFileDialog
                {
                    FileName   = "wenskaart",
                    DefaultExt = ".wns",
                    Filter     = "Wenskaarten|*.wns"
                };
                if (dlg.ShowDialog() == true)
                {
                    using (StreamWriter bestand = new StreamWriter(dlg.FileName))
                    {
                        string pad = Achtergrond.UriSource.AbsoluteUri.ToString();


                        bestand.WriteLine(AchtergrondNaam);
                        bestand.WriteLine(pad);

                        bestand.WriteLine(Ballen.Count);

                        foreach (Model.Bal bal in Ballen)
                        {
                            //bestand.WriteLine(bal.KleurBal.Naam + " " + bal.XPositie.ToString() + " " + bal.YPositie.ToString());
                            bestand.WriteLine(bal.KleurBal.Naam);
                            bestand.WriteLine(bal.XPositie.ToString());
                            bestand.WriteLine(bal.YPositie.ToString());
                        }

                        bestand.WriteLine(WensTekst);
                        bestand.WriteLine(SelectedFont.ToString());
                        bestand.WriteLine(LetterGrootte.ToString());
                    }
                    StatusBarTekst = dlg.FileName;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Opslaan mislukt: " + ex.Message);
            }
        }
Пример #3
0
        public ViewModel()
        {
            OutputText = InputText.Merge(SelectedFont)
                         .Select(i => (object)i)
                         .Merge(FontSize.Select(i => (object)i))
                         .Merge(SubWidth.Select(i => (object)i))
                         .Merge(IsBold.Select(i => (object)i))
                         .Merge(IsItalic.Select(i => (object)i))
                         .Merge(SmallerBreaking.Select(i => (object)i))
                         .Merge(BreakPerChars.Select(i => (object)i))
                         .Throttle(TimeSpan.FromMilliseconds(500))
                         .Select(i =>
            {
                if (InputText.Value != "" && FontSize.Value > 0 && SubWidth.Value > 10)
                {
                    return(Model.Optimize(InputText.Value, SelectedFont.Value,
                                          FontSize.Value, IsBold.Value, IsItalic.Value, SubWidth.Value,
                                          breakPerElement: SmallerBreaking.Value,
                                          breakPerCharacter: BreakPerChars.Value));
                }
                return("");
            })
                         .ToReactiveProperty();


            OutputText.Subscribe(_ => OnPropertyChanged(() => CopyResult));
            IsBold.Subscribe(_ => OnPropertyChanged(() => FontWeight));
            IsItalic.Subscribe(_ => OnPropertyChanged(() => FontStyle));
            SelectedFont.Subscribe(_ =>
            {
                if (Fonts.Contains(SelectedFont.Value) && Fonts.IndexOf(SelectedFont.Value) != SelectedFontIndex)
                {
                    SelectedFontIndex = Fonts.IndexOf(SelectedFont.Value);
                }
            });

            BreakPerBlock = true;
        }
Пример #4
0
        public GlyphCollection Raster()
        {
            if (SelectedFont == null)
            {
                throw new ArgumentNullException("The specified font to raster is Null.");
            }

            Logger.WriteLine("Starting font rasterization for %@", LogLevel.Message, SelectedFont.ToString());

            if (SortedUnicodeTable == null || SortedUnicodeTable.Count < 1)
            {
                LoadUnicodeTable();
            }

            SortedList <int, Glyph> glyphs = new SortedList <int, Glyph>(UnicodeTableData.Length);

            long     errors   = 0;
            long     warnings = 0;
            Bitmap   buffer   = new Bitmap(1024, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Graphics device   = Graphics.FromImage(buffer);

            device.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
            SizeF lastGlyphSize = device.MeasureString("X", SelectedFont, PointF.Empty, StringFormat.GenericTypographic);

            foreach (var info in UnicodeTableData)
            {
                try
                {
                    device.Clear(Color.White);
                    SizeF glyphSize = device.MeasureString(info.Literal, SelectedFont, PointF.Empty, StringFormat.GenericTypographic);
                    if (glyphSize.IsEmpty)
                    {
                        Logger.WriteLine("Cannot rasterize Glyph with code %@. Glyph not found inside source Font.", LogLevel.Warning, info.CodePoint);
                        warnings++;
                        continue;
                    }
                    if (glyphSize.Width < 1)
                    {
                        if (lastGlyphSize.Width < 1)
                        {
                            Logger.WriteLine("Glyph %@ doesnt have a valid width after string measurement. Making it square (%@).", LogLevel.Warning, info.CodePoint, lastGlyphSize.Width);
                            glyphSize.Width = glyphSize.Height;
                            warnings++;
                        }
                        else
                        {
                            Logger.WriteLine("Glyph %@ doesnt have a valid width after string measurement. Using previous glyph as template with value of %@.", LogLevel.Warning, info.CodePoint, lastGlyphSize.Width);
                            glyphSize.Width = lastGlyphSize.Width;
                            warnings++;
                        }
                    }
                    if (glyphSize.Height < 1)
                    {
                        if (lastGlyphSize.Height < 1)
                        {
                            Logger.WriteLine("Glyph %@ doesnt have a valid height after string measurement. Making it square (%@).", LogLevel.Warning, info.CodePoint, lastGlyphSize.Height);
                            glyphSize.Height = glyphSize.Width;
                            warnings++;
                        }
                        else
                        {
                            Logger.WriteLine("Glyph %@ doesnt have a valid height after string measurement. Using previous glyph as template  with value of %@.", LogLevel.Warning, info.CodePoint, lastGlyphSize.Height);
                            glyphSize.Height = lastGlyphSize.Height;
                            warnings++;
                        }
                    }

                    if (glyphSize.Width < 1 || glyphSize.Height < 1)
                    {
                        Logger.WriteLine("Cannot rasterize glyph with code %@. Cannot properly measure glyph size.", LogLevel.Error, info.CodePoint);
                        errors++;
                        continue;
                    }

                    lastGlyphSize = glyphSize;

                    Bitmap   bmp = new Bitmap((int)Math.Round(glyphSize.Width, 0), (int)Math.Round(glyphSize.Height, 0), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    g.Clear(Color.White);
                    g.DrawString(info.Literal, SelectedFont, Brushes.Black, Point.Empty, StringFormat.GenericTypographic);
                    g.Flush();
                    g.Dispose();

                    glyphs.Add(info.CodePoint, new Glyph(info, bmp));
                    bmp = null;
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Cannot raster Glyph with code %@. [%@] %@", LogLevel.Error, info.CodePoint, ex.GetType().Name, ex.Message);
                    errors++;
                    continue;
                }
            }

            device.Dispose();
            buffer.Dispose();

            Logger.WriteLine("Rasterized %@ glyphs using Font %@.", LogLevel.Message, glyphs.Count.ToString(), SelectedFont.ToString());
            if (errors > 0)
            {
                Logger.WriteLine("Could not rasterize %@ glyphs due to rasterization errors.", LogLevel.Warning, errors.ToString());
            }
            else
            {
                Logger.WriteLine("0 errors during the rasterization process.", LogLevel.Message);
            }
            Logger.WriteLine("%@ warnings found during the rasterization process.", (warnings > 0 ? LogLevel.Warning : LogLevel.Message), warnings.ToString());

            return(new GlyphCollection(glyphs));
        }