Пример #1
0
        private ISpatialText CorrectForCaptureArea(ISpatialText spatialText)
        {
            var captureAreaLocation = _ocrTranslateOverlayConfiguration.CaptureArea.Location;

            spatialText.Move(captureAreaLocation);
            return(spatialText);
        }
Пример #2
0
 public static SpatialTextViewModel ToViewModel(this ISpatialText text, string language)
 {
     return(new(
                text.Text,
                text.Area.ToModel()
                ));
 }
        public override ISpatialText Combine(ISpatialText spatialText)
        {
            _spatialTexts.Add(spatialText);

            Area  = Rectangle.Union(Area, spatialText.Area);
            Text += spatialText.Text;

            return(this);
        }
        private static bool BelongToSameText(ISpatialText textA, ISpatialText textB)
        {
            var maxDistanceA = textA.Metrics.AverageLetterWidth + textA.Metrics.AverageLetterHeight;
            var maxDistanceB = textB.Metrics.AverageLetterWidth + textB.Metrics.AverageLetterHeight;

            var areCloseEnoughForA = textA.Area.IsInDistance(textB.Area, maxDistanceA);
            var areCloseEnoughForB = textA.Area.IsInDistance(textB.Area, maxDistanceB);

            return(areCloseEnoughForA && areCloseEnoughForB);
        }
        private static (Rectangle compensatedArea, float compensatedFontScale) CompensateForRender(ISpatialText text)
        {
            //const float defaultFontScale = 0.4f;
            const int imGuiPadding = 8;

            var calculatedSize = ImGui.CalcTextSize(text.Text);

            var areaHeight = Math.Abs(text.Area.Height);
            var areaWidth  = Math.Abs(text.Area.Width);

            var estimatedTextArea     = calculatedSize.X * calculatedSize.Y;
            var additionalPaddingArea = areaWidth * imGuiPadding * 2 + areaHeight * imGuiPadding * 2 - imGuiPadding * imGuiPadding * 4;


            var neededArea    = estimatedTextArea + additionalPaddingArea;
            var availableArea = areaHeight * areaWidth;

            var missingArea = neededArea - availableArea;

            if (missingArea < 0)
            {
                var extraAreaFactor = availableArea / neededArea;

                return(text.Area, (float)Math.Sqrt(extraAreaFactor * 0.5));
            }

            var scaleFactor = Math.Sqrt(neededArea / availableArea);

            var missingHeight = scaleFactor * text.Area.Height - text.Area.Height;
            var missingWidth  = scaleFactor * text.Area.Width - text.Area.Width;

            var compensatedRectangle = Rectangle.Inflate(text.Area, (int)(missingWidth / 2), (int)(missingHeight / 2));

            return(compensatedRectangle, 0.8f);
        }
 public AccumulatedSpatialText(ISpatialText a) : base(a.Text, a.Area)
 {
     _spatialTexts.Add(a);
 }
 public virtual ISpatialText Combine(ISpatialText spatialText)
 {
     return(new AccumulatedSpatialText(this).Combine(spatialText));
 }