コード例 #1
0
 /// <summary>
 /// Converts an object into its XML representation.
 /// </summary>
 /// <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param>
 public void WriteXml(XmlWriter writer)
 {
     writer.WriteElementString("LineAlignment", LineAlignment.ToString());
     writer.WriteElementString("Alignment", Alignment.ToString());
     writer.WriteElementString("Trimming", Trimming.ToString());
     writer.WriteElementString("Xshift", Xshift.ToString());
     writer.WriteElementString("Yshift", Yshift.ToString());
     writer.WriteElementString("Font",
                               TypeDescriptor.GetConverter(Font).ConvertTo(Font, typeof(string)).ToString());
 }
コード例 #2
0
 public override bool Equals(object obj)
 {
     return((obj is StringFormat f) &&
            FormatFlags.Equals(f.FormatFlags) &&
            HotkeyPrefix.Equals(f.HotkeyPrefix) &&
            measurableCharacterRanges == f.measurableCharacterRanges &&
            Alignment.Equals(f.Alignment) &&
            LineAlignment.Equals(f.LineAlignment) &&
            Trimming.Equals(f.Trimming));
 }
コード例 #3
0
        protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory)
        {
            base.OnCreateDeviceIndependentResources(factory);
            this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", 72);
            this._textFormat.TextAlignment      = TextAlignment.Center;
            this._textFormat.ParagraphAlignment = ParagraphAlignment.Center;

            System.Globalization.CultureInfo ci = this._textFormat.Culture;
            Trimming trimming = this._textFormat.Trimming;
        }
コード例 #4
0
        public void ExecuteTest()
        {
            float max_err = 0;

            foreach (int batch in new int[] { 1, 2 })
            {
                foreach (int channels in new int[] { 3, 5 })
                {
                    foreach (int lefttrim in new int[] { 0, 1, 2 })
                    {
                        foreach (int righttrim in new int[] { 0, 1, 2 })
                        {
                            foreach (int toptrim in new int[] { 0, 1, 2 })
                            {
                                foreach (int bottomtrim in new int[] { 0, 1, 2 })
                                {
                                    foreach (int inwidth in new int[] { 5, 7, 11 })
                                    {
                                        foreach (int inheight in new int[] { 5, 7, 11 })
                                        {
                                            int outwidth = inwidth - lefttrim - righttrim, outheight = inheight - toptrim - bottomtrim;

                                            float[] xval = (new float[inwidth * inheight * channels * batch]).Select((_, idx) => idx * 1e-3f).ToArray();

                                            Map2D x = new Map2D(channels, inwidth, inheight, batch, xval);

                                            Map2D y = Reference(x, lefttrim, righttrim, toptrim, bottomtrim);

                                            OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, inwidth, inheight, batch), xval);
                                            OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map2D(channels, outwidth, outheight, batch));

                                            Trimming ope = new Trimming(inwidth, inheight, channels, lefttrim, righttrim, toptrim, bottomtrim, batch);

                                            ope.Execute(x_tensor, y_tensor);

                                            float[] y_expect = y.ToArray();
                                            float[] y_actual = y_tensor.State;

                                            CollectionAssert.AreEqual(xval, x_tensor.State);

                                            AssertError.Tolerance(y_expect, y_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {channels},{lefttrim},{righttrim},{toptrim},{bottomtrim},{inwidth},{inheight},{batch}");

                                            Console.WriteLine($"pass: {channels},{lefttrim},{righttrim},{toptrim},{bottomtrim},{inwidth},{inheight},{batch}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine($"maxerr:{max_err}");
        }
コード例 #5
0
        public override JObject SaveToJsonObject(StiJsonSaveMode mode)
        {
            var jObject = base.SaveToJsonObject(mode);

            jObject.Add(new JProperty("IsGeneric", IsGeneric));
            jObject.Add(new JProperty("Alignment", Alignment.ToString()));
            jObject.Add(new JProperty("FormatFlags", FormatFlags.ToString()));
            jObject.Add(new JProperty("HotkeyPrefix", HotkeyPrefix.ToString()));
            jObject.Add(new JProperty("LineAlignment", LineAlignment.ToString()));
            jObject.Add(new JProperty("Trimming", Trimming.ToString()));

            return(jObject);
        }
コード例 #6
0
        /// <inheritdoc />
        public override object Convert([NotNull] object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }
            if (values.Length != 2)
            {
                throw new ArgumentException("The number of provided bindings to this converter must be 2.");
            }

            var text = values[0]?.ToString() ?? string.Empty;

            if (values[1] is Control control)
            {
                return(Trimming.ProcessTrimming(control, text, TextTrimming, TrimmingSource, WordSeparators, MaxWidth));
            }
            if (values[1] is TextBlock textBlock)
            {
                return(Trimming.ProcessTrimming(textBlock, text, TextTrimming, TrimmingSource, WordSeparators, MaxWidth));
            }
            return(text);
        }
コード例 #7
0
        public void SpeedTest()
        {
            int inwidth = 512, channels = 32, lefttrim = 1, righttrim = 1;
            int outwidth = inwidth - lefttrim - righttrim;

            OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map1D(channels, inwidth));
            OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map1D(channels, outwidth));

            Trimming ope = new Trimming(inwidth, channels, lefttrim, righttrim);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            ope.Execute(x_tensor, y_tensor);
            ope.Execute(x_tensor, y_tensor);
            ope.Execute(x_tensor, y_tensor);
            ope.Execute(x_tensor, y_tensor);

            sw.Stop();

            Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec");
        }
コード例 #8
0
                /// <summary>
                /// Displays the specified text within the specified rectangular region.
                /// </summary>
                /// <param name="text">The text to display.</param>
                /// <param name="x">The X coordinate of the rectangular region.</param>
                /// <param name="y">The Y coordinate of the rectangular region.</param>
                /// <param name="width">The width of the rectangular region.</param>
                /// <param name="height">The height of the rectangular region.</param>
                /// <param name="color">The text color.</param>
                /// <param name="font">The text font.</param>
                /// <param name="textAlignment">A value from the <see cref="TextAlign"/> enumeration that specifies how to align the text within the rectangular region.</param>
                /// <param name="wordWrap">A value from the <see cref="WordWrap"/> enumeration that specifies how to wrap the text within the rectangular region.</param>
                /// <param name="trimming">A value from the <see cref="Trimming"/> enumeration that specifies how to trim excess text.</param>
                /// <param name="scaleTextToFit">A value from the <see cref="ScaleText"/> enumeration that specifies how the text should be scaled.</param>
                public void DisplayTextInRectangle(string text, uint x, uint y, uint width, uint height,
                    Color color, Font font, TextAlign textAlignment, WordWrap wordWrap, Trimming trimming, ScaleText scaleTextToFit)
                {
                    uint dtFlags = Bitmap.DT_None;

                    switch (textAlignment)
                    {
                        case TextAlign.Center:
                            dtFlags |= Bitmap.DT_AlignmentCenter;
                            break;
                        case TextAlign.Left:
                            dtFlags |= Bitmap.DT_AlignmentLeft;
                            break;
                        case TextAlign.Right:
                            dtFlags |= Bitmap.DT_AlignmentRight;
                            break;
                        default:
                            break;
                    }

                    switch (trimming)
                    {
                        case Trimming.CharacterEllipsis:
                            dtFlags |= Bitmap.DT_TrimmingCharacterEllipsis;
                            break;
                        case Trimming.WordEllipsis:
                            dtFlags |= Bitmap.DT_TrimmingWordEllipsis;
                            break;
                        default:
                            break;
                    }


                    if (wordWrap == WordWrap.Wrap)
                        dtFlags |= Bitmap.DT_WordWrap;

                    if (scaleTextToFit == ScaleText.None)
                        dtFlags |= Bitmap.DT_IgnoreHeight;

                    _display.DrawTextInRect(text, (int)x, (int)y, (int)width, (int)height, dtFlags, color, font);

                    if (AutoRedraw) Redraw();
                }
コード例 #9
0
                /// <summary>
                /// Displays the specified text within the specified rectangular region.
                /// </summary>
                /// <param name="text">The text to display.</param>
                /// <param name="x">The X coordinate of the rectangular region.</param>
                /// <param name="y">The Y coordinate of the rectangular region.</param>
                /// <param name="width">The width of the rectangular region.</param>
                /// <param name="height">The height of the rectangular region.</param>
                /// <param name="color">The text color.</param>
                /// <param name="font">The text font.</param>
                /// <param name="textAlignment">A value from the <see cref="TextAlign"/> enumeration that specifies how to align the text within the rectangular region.</param>
                /// <param name="wordWrap">A value from the <see cref="WordWrap"/> enumeration that specifies how to wrap the text within the rectangular region.</param>
                /// <param name="trimming">A value from the <see cref="Trimming"/> enumeration that specifies how to trim excess text.</param>
                /// <param name="scaleTextToFit">A value from the <see cref="ScaleText"/> enumeration that specifies how the text should be scaled.</param>
                public void DisplayTextInRectangle(string text, uint x, uint y, uint width, uint height,
                                                   Color color, Font font, TextAlign textAlignment, WordWrap wordWrap, Trimming trimming, ScaleText scaleTextToFit)
                {
                    uint dtFlags = Bitmap.DT_None;

                    switch (textAlignment)
                    {
                    case TextAlign.Center:
                        dtFlags |= Bitmap.DT_AlignmentCenter;
                        break;

                    case TextAlign.Left:
                        dtFlags |= Bitmap.DT_AlignmentLeft;
                        break;

                    case TextAlign.Right:
                        dtFlags |= Bitmap.DT_AlignmentRight;
                        break;

                    default:
                        break;
                    }

                    switch (trimming)
                    {
                    case Trimming.CharacterEllipsis:
                        dtFlags |= Bitmap.DT_TrimmingCharacterEllipsis;
                        break;

                    case Trimming.WordEllipsis:
                        dtFlags |= Bitmap.DT_TrimmingWordEllipsis;
                        break;

                    default:
                        break;
                    }


                    if (wordWrap == WordWrap.Wrap)
                    {
                        dtFlags |= Bitmap.DT_WordWrap;
                    }

                    if (scaleTextToFit == ScaleText.None)
                    {
                        dtFlags |= Bitmap.DT_IgnoreHeight;
                    }

                    _display.DrawTextInRect(text, (int)x, (int)y, (int)width, (int)height, dtFlags, color, font);

                    if (AutoRedraw)
                    {
                        Redraw();
                    }
                }
コード例 #10
0
                /// <summary>
                /// Displays the specified text within the specified rectangular region.
                /// </summary>
                /// <param name="text">The text to display.</param>
                /// <param name="x">The X coordinate of the rectangular region.</param>
                /// <param name="y">The Y coordinate of the rectangular region.</param>
                /// <param name="width">The width of the rectangular region.</param>
                /// <param name="height">The height of the rectangular region.</param>
                /// <param name="color">The text color.</param>
                /// <param name="font">The text font.</param>
                /// <param name="textAlignment">A value from the <see cref="TextAlign"/> enumeration that specifies how to align the text within the rectangular region.</param>
                /// <param name="wordWrap">A value from the <see cref="WordWrap"/> enumeration that specifies how to wrap the text within the rectangular region.</param>
                /// <param name="trimming">A value from the <see cref="Trimming"/> enumeration that specifies how to trim excess text.</param>
                /// <param name="scaleTextToFit">A value from the <see cref="ScaleText"/> enumeration that specifies how the text should be scaled.</param>
                public void DisplayTextInRectangle(string text, int x, int y, int width, int height,
                    Color color, Font font, TextAlign textAlignment, WordWrap wordWrap, Trimming trimming, ScaleText scaleTextToFit)
                {
                    uint dtFlags = Bitmap.DT_None;

                    switch (textAlignment)
                    {
                        case TextAlign.Center:
                            dtFlags |= Bitmap.DT_AlignmentCenter;
                            break;
                        case TextAlign.Left:
                            dtFlags |= Bitmap.DT_AlignmentLeft;
                            break;
                        case TextAlign.Right:
                            dtFlags |= Bitmap.DT_AlignmentRight;
                            break;
                        default:
                            break;
                    }

                    switch (trimming)
                    {
                        case Trimming.CharacterEllipsis:
                            dtFlags |= Bitmap.DT_TrimmingCharacterEllipsis;
                            break;
                        case Trimming.WordEllipsis:
                            dtFlags |= Bitmap.DT_TrimmingWordEllipsis;
                            break;
                        default:
                            break;
                    }


                    if (wordWrap == WordWrap.Wrap)
                        dtFlags |= Bitmap.DT_WordWrap;

                    if (scaleTextToFit == ScaleText.None)
                        dtFlags |= Bitmap.DT_IgnoreHeight;

                    _screen.DrawTextInRect(text, x, y, width, height, dtFlags, color, font);

                    if (_autoRedraw)
                    {
                        if (_redrawAll)
                        {
                            _displayModule.Paint(_screen, 0, 0, _width, _height);
                            _redrawAll = false;
                        }
                        else
                        {
                            int right, bottom;
                            font.ComputeTextInRect(text, out right, out bottom, 0, 0, width, height, dtFlags);

                            right += x;
                            bottom += y;

                            if (right >= _width) right = _width - 1;
                            if (bottom >= _height) bottom = _height - 1;

                            if (x < 0) x = 0;
                            if (y < 0) y = 0;

                            if (right >= 0 && bottom >= 0 && x < _width && y < _height)
                                _displayModule.Paint(_screen, x, y, right - x + 1, bottom - y + 1);
                        }
                    }
                }