Esempio n. 1
0
        public void Draw(RenderContext renderContext, float opacity, Color color)
        {
            if (renderContext.gl == null)
            {
                Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform);

                double drawHeight = (Height / renderContext.FovAngle) * renderContext.Height / 180;

                foreach (Text3d t3d in Items)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(t3d.center);
                    if (screenSpacePnt.Z < 0)
                    {
                        continue;
                    }

                    if (Vector3d.Dot((Vector3d)viewPoint, (Vector3d)t3d.center) < .55)
                    {
                        continue;
                    }

                    Vector3d screenSpaceTop = renderContext.WVP.Transform(t3d.top);

                    double rotation = Math.Atan2(screenSpacePnt.X - screenSpaceTop.X, screenSpacePnt.Y - screenSpaceTop.Y);


                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();

                    ctx.Translate(screenSpacePnt.X, screenSpacePnt.Y);
                    ctx.Rotate(-rotation); // todo update with up vector
                    ctx.Alpha        = opacity;
                    ctx.FillStyle    = color.ToString();
                    ctx.Font         = "normal" + " " + (false ? "bold" : "normal") + " " + Math.Round(drawHeight * 1.2).ToString() + "px " + "Arial";
                    ctx.TextBaseline = TextBaseline.Top;

                    TextMetrics tm = ctx.MeasureText(t3d.Text);

                    ctx.FillText(t3d.Text, -tm.Width / 2, -drawHeight / 2);
                    ctx.Restore();
                }
            }
            else
            {
                // gl version
                if (glyphCache == null || glyphCache.Version > glyphVersion)
                {
                    PrepareBatch();
                }
                if (glyphCache.Ready == false)
                {
                    return;
                }


                TextShader.Use(renderContext, vertexBuffer.VertexBuffer, glyphCache.Texture.Texture2d);

                renderContext.gl.drawArrays(GL.TRIANGLES, 0, vertexBuffer.Count);
            }
        }
        protected void RedrawBaseTextImage()
        {
            UpdateFont();
            string[] lines = _Text.Split('\n');
            float    H     = FontSize * 1f;


            int W = 0;
            int i = 0;

            while (i < lines.Length)
            {
                TextMetrics TM = TextGraphic.MeasureText(lines[i]);
                W = Math.Max(W, (int)Math.Ceiling(TM.Width));
                i++;
            }
            //TextImage.Height = (int)(H * (lines.Length+0.5f));
            TextImage.Height = (int)(H * (lines.Length + 0.25f));
            TextImage.Width  = W;
            UpdateFont();

            float Y = 0;

            i = 0;
            while (i < lines.Length)
            {
                TextGraphic.FillText(lines[i], 0, (int)(FontSize + Y));
                Y += H;
                i++;
            }

            textInvallidated  = false;
            imageInvallidated = true;
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="directWriteFactory"></param>
        /// <param name="caption"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public Button(SharpDX.DirectWrite.Factory directWriteFactory, string caption, float x, float y, float width = BUTTON_STANDARD_WIDTH, float height = BUTTON_STANDARD_HEIGHT)
        {
            Caption = caption;
            X       = x;
            Y       = y;
            Width   = width;
            Height  = height;

            hovered = false;
            pressed = false;

            TextColor = SolidColorBrushes.White;

            roundedRectangle         = new RoundedRectangle();
            roundedRectangle.RadiusX = 8;
            roundedRectangle.RadiusY = 8;

            rect = new RectangleF(x, y, width, height);
            roundedRectangle.Rect = rect;

            textLayout = new TextLayout(directWriteFactory, caption, FormFonts.ButtonNormalFont, width, height);
            TextMetrics textMetrics = textLayout.Metrics;

            textPosition = new Vector2(x + ((width / 2f) - (textMetrics.Width / 2f)), y + ((height / 2f) - (textMetrics.Height / 2f)));
        }
Esempio n. 4
0
        private void DetermineMaxItemSize(IDrawingContext dc, Item[] items, out SizeInt32 maxItemSizeResult, out SizeInt32 maxImageSizeResult)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;

            foreach (Item item in items)
            {
                num  = Math.Max(num, (item.Image == null) ? 0 : item.Image.Width);
                num2 = Math.Max(num2, (item.Image == null) ? 0 : item.Image.Height);
                TextLayoutAlgorithm?layoutAlgorithm = null;
                TextLayout          resourceSource  = UIText.CreateLayout(dc, item.Name, this.Font, layoutAlgorithm, HotkeyRenderMode.Ignore, 65535.0, 65535.0);
                TextMetrics         metrics         = dc.GetCachedOrCreateResource <ITextLayout>(resourceSource).Metrics;
                SizeInt32           num9            = new SizeInt32((int)Math.Ceiling((double)metrics.WidthMax), (int)Math.Ceiling((double)metrics.Height));
                num3 = Math.Max(num9.Width, num3);
                num4 = Math.Max(num9.Height, num4);
            }
            int recommendedExtent = this.dropShadowRenderer.GetRecommendedExtent(num, num2);
            int width             = ((((((recommendedExtent + this.imageXInset) + num) + this.imageXInset) + recommendedExtent) + this.textLeftMargin) + num3) + this.textRightMargin;
            int height            = Math.Max((int)((((this.imageYInset + recommendedExtent) + num2) + this.imageYInset) + recommendedExtent), (int)((this.textVMargin + num4) + this.textVMargin));

            maxItemSizeResult  = new SizeInt32(width, height);
            maxImageSizeResult = new SizeInt32(num, num2);
        }
Esempio n. 5
0
        public TextInfo GetTextInfo(Graphics graphics, Font font)
        {
            TextMetrics metrics = visualStyleRenderer.GetTextMetrics(graphics);
            TextInfo    info    = new TextInfo();

            info.Height = metrics.Height;
            return(info);
        }
Esempio n. 6
0
        public void SciterPoint_width_and_height_from_ctor(float minWidth, float maxWidth, float height, float ascent, float descent, int noLines)
        {
            var actual = new TextMetrics(minWidth, maxWidth, height, ascent, descent, noLines);

            Assert.AreEqual(ascent, actual.Ascent);
            Assert.AreEqual(descent, actual.Descent);
            Assert.AreEqual(height, actual.Height);
            Assert.AreEqual(noLines, actual.LineCount);
            Assert.AreEqual(maxWidth, actual.MaxWidth);
            Assert.AreEqual(minWidth, actual.MinWidth);
        }
Esempio n. 7
0
        public Column(SharpDX.DirectWrite.Factory directWriteFactory, string caption, string fieldName, float width, float height)
        {
            Caption   = caption;
            FieldName = fieldName;
            Width     = width;
            Height    = height;

            TextLayout = new TextLayout(directWriteFactory, caption, FormFonts.ColumnHeaderFont, width, height);
            TextMetrics textMetrics = TextLayout.Metrics;

            TextLayout.ParagraphAlignment = ParagraphAlignment.Near;
        }
Esempio n. 8
0
        // Token: 0x0600019D RID: 413 RVA: 0x00014520 File Offset: 0x00012720
        public Vector2 MeasureText(string text, float fontSize = 13f, string fontFamily = "Calibri")
        {
            TextFormat orCreate = this.textFormatCache.GetOrCreate(fontFamily, fontSize);
            Vector2    result;

            using (TextLayout textLayout = new TextLayout(this.context.DirectWrite, text, orCreate, float.MaxValue, float.MaxValue))
            {
                TextMetrics metrics = textLayout.Metrics;
                result = new Vector2(metrics.Width, metrics.Height);
            }
            return(result);
        }
Esempio n. 9
0
 public static Point ApplyTextAlign(Point point, string align, string text, TextMetrics size)
 {
     switch (align)
     {
         case "left":
             return point;
         case "center":
             return new Point(point.X - size.width/2f, point.Y);
         case "right":
             return new Point(point.X - size.width, point.Y);
     }
     return point;
 }
Esempio n. 10
0
        public void TextMetrics_AverageCharWidth_Set_GetReturnsExpected(int value)
        {
            var metric = new TextMetrics
            {
                AverageCharWidth = value
            };

            Assert.Equal(value, metric.AverageCharWidth);

            // Set same.
            metric.AverageCharWidth = value;
            Assert.Equal(value, metric.AverageCharWidth);
        }
Esempio n. 11
0
        public void TextMetrics_BreakChar_Set_GetReturnsExpected(char value)
        {
            var metric = new TextMetrics
            {
                BreakChar = value
            };

            Assert.Equal(value, metric.BreakChar);

            // Set same.
            metric.BreakChar = value;
            Assert.Equal(value, metric.BreakChar);
        }
Esempio n. 12
0
        public void TextMetrics_CharSet_Set_GetReturnsExpected(TextMetricsCharacterSet value)
        {
            var metric = new TextMetrics
            {
                CharSet = value
            };

            Assert.Equal(value, metric.CharSet);

            // Set same.
            metric.CharSet = value;
            Assert.Equal(value, metric.CharSet);
        }
Esempio n. 13
0
        public void TextMetrics_Ascent_Set_GetReturnsExpected(int value)
        {
            var metric = new TextMetrics
            {
                Ascent = value
            };

            Assert.Equal(value, metric.Ascent);

            // Set same.
            metric.Ascent = value;
            Assert.Equal(value, metric.Ascent);
        }
Esempio n. 14
0
        public void TextMetrics_Underlined_Set_GetReturnsExpected(bool value)
        {
            var metric = new TextMetrics
            {
                Underlined = value
            };

            Assert.Equal(value, metric.Underlined);

            // Set same.
            metric.Underlined = value;
            Assert.Equal(value, metric.Underlined);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            var messages = new TextMessages();
            var repo     = new TextRepository();
            var metrics  = new TextMetrics();

            Console.WriteLine("Listening for ExchangeTextRankCalculated event, press Ctrl+C to stop...");
            messages.ConsumeMessagesInLoop(TextMessages.QueueTextSuccessMarker, TextMessages.ExchangeTextRankCalculated, (model, json) => {
                var message           = TextRankCalculatedMessage.FromJson(json);
                bool isTextSuccessful = (message.Score > minSuccessfulScore);
                messages.SendTextSuccessMarked(message.ContextId, isTextSuccessful);
            });
        }
Esempio n. 16
0
        public void TextMetrics_PitchAndFamily_GetReturnsExpected(TextMetricsPitchAndFamilyValues value)
        {
            var metric = new TextMetrics
            {
                PitchAndFamily = value
            };

            Assert.Equal(value, metric.PitchAndFamily);

            // Set same.
            metric.PitchAndFamily = value;
            Assert.Equal(value, metric.PitchAndFamily);
        }
Esempio n. 17
0
        public void TextMetrics_StruckOut_Set_GetReturnsExpected(bool value)
        {
            var metric = new TextMetrics
            {
                StruckOut = value
            };

            Assert.Equal(value, metric.StruckOut);

            // Set same.
            metric.StruckOut = value;
            Assert.Equal(value, metric.StruckOut);
        }
Esempio n. 18
0
        public void TextMetrics_Italic_Set_GetReturnsExpected(bool value)
        {
            var metric = new TextMetrics
            {
                Italic = value
            };

            Assert.Equal(value, metric.Italic);

            // Set same.
            metric.Italic = value;
            Assert.Equal(value, metric.Italic);
        }
Esempio n. 19
0
        public void TextMetrics_Overhang_Set_GetReturnsExpected(int value)
        {
            var metric = new TextMetrics
            {
                Overhang = value
            };

            Assert.Equal(value, metric.Overhang);

            // Set same.
            metric.Overhang = value;
            Assert.Equal(value, metric.Overhang);
        }
Esempio n. 20
0
        public void TextMetrics_InternalLeading_Set_GetReturnsExpected(int value)
        {
            var metric = new TextMetrics
            {
                InternalLeading = value
            };

            Assert.Equal(value, metric.InternalLeading);

            // Set same.
            metric.InternalLeading = value;
            Assert.Equal(value, metric.InternalLeading);
        }
Esempio n. 21
0
        public void TextMetrics_DigitizedAspectY_Set_GetReturnsExpected(int value)
        {
            var metric = new TextMetrics
            {
                DigitizedAspectY = value
            };

            Assert.Equal(value, metric.DigitizedAspectY);

            // Set same.
            metric.DigitizedAspectY = value;
            Assert.Equal(value, metric.DigitizedAspectY);
        }
        static void Main(string[] args)
        {
            var messages = new TextMessages();
            var repo     = new TextRepository();
            var metrics  = new TextMetrics();

            Console.WriteLine("Listening for ExchangeProcessingAccepted event, press Ctrl+C to stop...");
            messages.ConsumeMessagesInLoop(TextMessages.QueueTextRancCalc, TextMessages.ExchangeProcessingAccepted, (model, json) => {
                var message = TextProcessingAcceptedMessage.FromJson(json);
                if (message.Accepted)
                {
                    messages.SendTextRankTask(message.ContextId);
                }
            });
        }
Esempio n. 23
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            float y = 0;

            for (int index = 0; index < this._paragraphs.Count; ++index)
            {
                using (TextFormat textFormat = DirectWriteFactory.CreateTextFormat(
                           this._paragraphs[index].FontFamily,
                           this._paragraphs[index].Weight,
                           this._paragraphs[index].FontSize * 96f / 72f))
                {
                    textFormat.TextAlignment = _paragraphs[index].TextAlignment;
                    LineSpacing lineSpacing = textFormat.LineSpacing;

                    if (_paragraphs[index].LineSpacing == 0)
                    {
                        textFormat.LineSpacing = LineSpacing.Default;
                    }
                    else
                    {
                        textFormat.LineSpacing = new LineSpacing(_paragraphs[index].LineSpacing);
                    }

                    float width = ClientSize.Width / DpiScaleX - (_marginLeft + _marginRight);

                    using (TextLayout textLayout = DirectWriteFactory.CreateTextLayout(
                               this._paragraphs[index].Text,
                               textFormat,
                               width,
                               0))
                    {
                        y += _paragraphs[index].SpaceBefore;

                        renderTarget.DrawTextLayout(
                            new PointF(_marginLeft, y),
                            textLayout,
                            _blackBrush,
                            DrawTextOptions.None);

                        TextMetrics metrics = textLayout.Metrics;

                        y += metrics.Height + _paragraphs[index].SpaceAfter;
                    }
                }
            }
        }
Esempio n. 24
0
        public void SciterPoint_set_width_and_height_from_property(float minWidth, float maxWidth, float height, float ascent, float descent, int noLines)
        {
            var actual = new TextMetrics
            {
                Ascent    = ascent,
                Descent   = descent,
                Height    = height,
                LineCount = noLines,
                MaxWidth  = maxWidth,
                MinWidth  = minWidth,
            };

            Assert.AreEqual(ascent, actual.Ascent);
            Assert.AreEqual(descent, actual.Descent);
            Assert.AreEqual(height, actual.Height);
            Assert.AreEqual(noLines, actual.LineCount);
            Assert.AreEqual(maxWidth, actual.MaxWidth);
            Assert.AreEqual(minWidth, actual.MinWidth);
        }
Esempio n. 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="directWriteFactory"></param>
        /// <param name="text"></param>
        /// <param name="textFormat"></param>
        /// <param name="textColor"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="center"></param>
        public Label(SharpDX.DirectWrite.Factory directWriteFactory, string text, TextFormat textFormat, SolidColorBrush textColor, float x, float y, float width, float height, bool center = false)
        {
            TextColor  = textColor;
            Text       = text;
            Centered   = center;
            TextFormat = textFormat;
            TextLayout = new TextLayout(directWriteFactory, text, textFormat, width, height);
            TextLayout.ParagraphAlignment = ParagraphAlignment.Near;
            TextMetrics textMetrics = TextLayout.Metrics;

            if (center)
            {
                TextPosition = new Vector2(x - (textMetrics.Width / 2f), y - (textMetrics.Height / 2f));
            }
            else
            {
                TextPosition = new Vector2(x, y);
            }
        }
Esempio n. 26
0
        static void Main(string[] args)
        {
            var messages = new TextMessages();
            var repo     = new TextRepository();
            var metrics  = new TextMetrics();

            Console.WriteLine("Listening for ExchangeTextRankTask event, press Ctrl+C to stop...");
            messages.ConsumeMessagesInLoop(TextMessages.QueueVowelConsCounter, TextMessages.ExchangeTextRankTask, (model, id) => {
                try
                {
                    string text    = repo.GetText(id);
                    int vowelCount = metrics.GetVowelCount(text);
                    int consCount  = metrics.GetConsonantsCount(text);
                    messages.SendTextScoreTask(id, vowelCount, consCount);
                    Console.WriteLine(id + " vowel count: " + vowelCount + ", cons count: " + consCount);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("exception occured: " + ex.ToString());
                }
            });
        }
        static void Main(string[] args)
        {
            int remainingAccepts = processingLimit;

            var messages = new TextMessages();
            var repo     = new TextRepository();
            var metrics  = new TextMetrics();

            Console.WriteLine("Listening for ExchangeText/ExchangeTextSuccessMarked events, press Ctrl+C to stop...");

            using (var connection = messages.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    messages.ListenMessages(channel, TextMessages.QueueTextProcessingLimiter, TextMessages.ExchangeText, (model, id) => {
                        Console.WriteLine("captured text '" + repo.GetText(id) + "' with id=" + id);
                        bool accepted = false;
                        if (remainingAccepts > 0)
                        {
                            --remainingAccepts;
                            accepted = true;
                        }
                        repo.SetTextStatus(id, accepted ? TextStatus.Accepted : TextStatus.Rejected);
                        messages.SendProcessingAccepted(id, accepted);
                    });
                    messages.ListenMessages(channel, TextMessages.QueueTextProcessingLimiterRevoke, TextMessages.ExchangeTextSuccessMarked, (model, json) => {
                        var message = TextSuccessMarkedMessage.FromJson(json);
                        repo.SetTextStatus(message.ContextId, TextStatus.Ready);
                        Console.WriteLine("revoke transaction for successful text '" + repo.GetText(message.ContextId) + "' with id=" + message.ContextId);
                        if (message.Success)
                        {
                            ++remainingAccepts;
                        }
                    });
                    while (true)
                    {
                        Thread.Sleep(Timeout.Infinite);
                    }
                }
        }
Esempio n. 28
0
        public void TextMetrics_Ctor_Default()
        {
            var metric = new TextMetrics();

            Assert.Equal(0, metric.Ascent);
            Assert.Equal(0, metric.AverageCharWidth);
            Assert.Equal('\0', metric.BreakChar);
            Assert.Equal(TextMetricsCharacterSet.Ansi, metric.CharSet);
            Assert.Equal('\0', metric.DefaultChar);
            Assert.Equal(0, metric.Descent);
            Assert.Equal(0, metric.DigitizedAspectX);
            Assert.Equal(0, metric.DigitizedAspectY);
            Assert.Equal(0, metric.ExternalLeading);
            Assert.Equal('\0', metric.FirstChar);
            Assert.Equal(0, metric.Height);
            Assert.Equal(0, metric.InternalLeading);
            Assert.False(metric.Italic);
            Assert.Equal(0, metric.MaxCharWidth);
            Assert.Equal(0, metric.Overhang);
            Assert.Equal((TextMetricsPitchAndFamilyValues)0, metric.PitchAndFamily);
            Assert.False(metric.StruckOut);
            Assert.False(metric.Underlined);
            Assert.Equal(0, metric.Weight);
        }
Esempio n. 29
0
 public static extern int GetTextMetrics(IntPtr DC, ref TextMetrics Metrics);
 public static extern int GetThemeTextMetrics(HandleRef hTheme, HandleRef hdc, int iPartId, int iStateId, ref TextMetrics ptm);
Esempio n. 31
0
        public unsafe static HRESULT GetThemeTextMetrics(IHandle hTheme, HandleRef hdc, int iPartId, int iStateId, out TextMetrics ptm)
        {
            HRESULT hr = GetThemeTextMetrics(hTheme.Handle, hdc.Handle, iPartId, iStateId, out ptm);

            GC.KeepAlive(hTheme);
            GC.KeepAlive(hdc.Wrapper);
            return(hr);
        }