/// <summary>
        /// Builds the watermark for the uploaded image of the machine state.
        /// </summary>
        /// <param name="windowHandle">The window handle to use.</param>
        /// <returns>The <see cref="TextLayer"/> to use.</returns>
        private TextLayer BuildWatermark(IntPtr windowHandle)
        {
            TextLayer watermark;
            Rect      rect;
            int       width;
            int       height;


            rect = new Rect();

            User32.GetWindowRect(windowHandle, ref rect);

            width  = rect.right - rect.left;
            height = rect.bottom - rect.top;

            watermark = new TextLayer {
                Text      = "© GTA Session Bot",
                Position  = new System.Drawing.Point(width - 480, height - 60),
                FontColor = System.Drawing.Color.White,
                FontSize  = 50,
                Opacity   = 75
            };


            return(watermark);
        }
Exemple #2
0
        /// <summary>
        /// The position in the original string where the first character of the captured substring was found.
        /// </summary>
        /// <param name="queryString">
        /// The query string to search.
        /// </param>
        /// <returns>
        /// The zero-based starting position in the original string where the captured substring was found.
        /// </returns>
        public int MatchRegexIndex(string queryString)
        {
            this.SortOrder = int.MaxValue;
            Match match = this.RegexPattern.Match(queryString);

            if (match.Success)
            {
                this.SortOrder = match.Index;
                NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString);
                TextLayer           textLayer       = new TextLayer
                {
                    Text        = this.ParseText(queryCollection),
                    Position    = this.ParsePosition(queryCollection),
                    FontColor   = this.ParseColor(queryCollection),
                    FontSize    = this.ParseFontSize(queryCollection),
                    FontFamily  = this.ParseFontFamily(queryCollection),
                    Style       = this.ParseFontStyle(queryCollection),
                    DropShadow  = this.ParseDropShadow(queryCollection),
                    Vertical    = this.ParseVertical(queryCollection),
                    RightToLeft = this.ParseRightToLeft(queryCollection)
                };

                textLayer.Opacity = this.ParseOpacity(queryCollection, textLayer.FontColor);

                this.Processor.DynamicParameter = textLayer;
            }

            return(this.SortOrder);
        }
Exemple #3
0
        /// <summary>
        /// Called by the layer to update the score layer for the present game state.
        /// </summary>
        public void update_layer()
        {
            ((ScoreLayer)this.layer).layers.Clear();
            if (this.Game.Players.Count <= 1)
            {
                this.update_layer_1p();
            }
            else
            {
                this.update_layer_4p();
            }

            // Common: add the ball X ... FREE PLAY footer
            TextLayer common = new TextLayer(128 / 2, 32 - 6, this.font_common, FontJustify.Center);

            if (this.Game.ball == 0)
            {
                common.set_text("FREE PLAY");
            }
            else
            {
                common.set_text(String.Format("BALL {0}            FREE PLAY", this.Game.ball));
            }

            ((ScoreLayer)this.layer).layers.Add(common);
        }
Exemple #4
0
        public static void Run()
        {
            // ExStart:UpdateTextLayerInPSDFile
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_PSD();

            try
            {
                // Load a PSD file as an image and caste it into PsdImage
                using (PsdImage image = (PsdImage)Image.Load(dataDir + "samplePsd.psd"))
                {
                    PsdImage  psdImage   = image;
                    TextLayer textLayer1 = psdImage.Layers[1] as TextLayer;
                    TextLayer textLayer2 = psdImage.Layers[2] as TextLayer;
                    Debug.Assert(textLayer2 != null, "textLayer2 != null");
                    textLayer2.UpdateText("test update", new Point(100, 100), 72.0f, Color.Purple);
                    psdImage.Save(dataDir + "UpdateTextLayerInPSDFile_out.psd", new PsdOptions {
                        CompressionMethod = CompressionMethod.RLE
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:UpdateTextLayerInPSDFile
        }
Exemple #5
0
 private Task ProcessMemeballMeme(string text, MemoryStream stream)
 {
     using (ImageProcessor.ImageFactory ifact = new ImageProcessor.ImageFactory()) {
         //TEXT WILL BE 32 CHARACTERS PER LINE, AT A 30 PIXEL HEIGHT IN ARIAL FONT
         //IMAGE ITSELF IS 450 PIXELS HIGH, ADD 34 PX PER LINE OF TEXT
         //TOTAL CANVAS IS 850 PX HIGH,
         String[] words = text.Split(' ');
         ifact.Load($"resources/mball/{words[0]}.png");
         string memetext    = "";
         int    lines       = 0;
         string currentline = "";
         for (int i = 1; i < words.Length; ++i)
         {
             string word = words[i];
             if ((currentline + word).Length >= 32)
             {
                 memetext += (currentline + "\n");
                 ++lines;
                 currentline = "";
             }
             currentline += (word + " ");
         }
         memetext += currentline;
         TextLayer tl = new TextLayer();
         tl.Position   = new Point(68, (380 - (34 * lines)));
         tl.FontSize   = 30;
         tl.FontFamily = FontFamily.GenericSansSerif;
         tl.Text       = memetext;
         tl.FontColor  = System.Drawing.Color.Black;
         ifact.Watermark(tl);
         ifact.Crop(new Rectangle(0, (374 - (34 * lines)), 592, 850 - (374 - (34 * lines))));
         ifact.Save(stream);
         return(Task.FromResult <object>(null));
     }
 }
        public List <byte[]> ProcessData(List <byte[]> input)
        {
            if (input.Count < InputQty)
            {
                return(null);
            }

            string text = Encoding.ASCII.GetString(input[1]);

            using (MemoryStream inStream = new MemoryStream(input[0]))
                using (MemoryStream outStream = new MemoryStream())
                {
                    using (ImageFactory imageFactory = new ImageFactory())
                    {
                        TextLayer textLayer = new TextLayer {
                            Text = text
                        };
                        imageFactory
                        .Load(inStream)
                        .Watermark(textLayer)
                        .Quality(100)
                        .Format(new JpegFormat())
                        .Save(outStream);
                    }

                    List <byte[]> output = new List <byte[]>();
                    output.Add(outStream.ToArray());

                    return(output);
                }
        }
Exemple #7
0
        public static void Run()
        {
            //ExStart:SetTextLayerPosition
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_PSD();

            string sourceFileName = dataDir + "OneLayer.psd";
            string exportPath     = dataDir + "OneLayer_Edited.psd";
            int    leftPos        = 99;
            int    topPos         = 47;
            var    im             = (PsdImage)Image.Load(sourceFileName);

            using (im)
            {
                im.AddTextLayer("Some text", new Rectangle(leftPos, topPos, 99, 47));
                TextLayer textLayer = (TextLayer)im.Layers[1];
                if (textLayer.Left != leftPos || textLayer.Top != topPos)
                {
                    throw new Exception("Was created incorrect Text Layer");
                }

                im.Save(exportPath);
            }

            //ExEnd:SetTextLayerPosition
        }
Exemple #8
0
        override public bool Execute()
        {
            var layer = new TextLayer(ActiveImage, 10, 10, _text, 0, true,
                                      48, SizeType.Points, "Sans");

            return(true);
        }
        public override bool Execute()
        {
            Layer layer = new TextLayer(ActiveImage, 10, 10, _text, 0, true,
                  48, SizeType.Points, "Sans");

              return true;
        }
        public override ILayer Clone()
        {
            TextFrameLayer layer = new TextFrameLayer();

            TextLayer.FontCopyWith(this, layer);
            LayerBase.CopyWith(this, layer);
            return(layer);
        }
Exemple #11
0
 public TextLayerDocumentHighlighter(HighlightingColorizer colorizer, TextLayer textLayer, HighlightingRuleSet baseRuleSet)
     : base(textLayer.Document, baseRuleSet)
 {
     Debug.Assert(colorizer != null);
     Debug.Assert(textLayer != null);
     this.colorizer = colorizer;
     this.textLayer = textLayer;
 }
        public void TestTextLayersUnmodifiableFields()
        {
            var          textLayer = new TextLayer();
            const string testValue = "some value";

            Assert.Throws <InvalidOperationException>(() => textLayer.ResourceType(testValue));
            Assert.Throws <InvalidOperationException>(() => textLayer.Format(testValue));
            Assert.Throws <InvalidOperationException>(() => textLayer.Type(testValue));
        }
Exemple #13
0
        public void TestWaterMarkRegex()
        {
            Dictionary <string, TextLayer> data = new Dictionary <string, TextLayer>
            {
                {
                    "watermark=text-watermark goodness,color-fff,size-36,style-italic,opacity-80,position-30,150,shadow-true,font-arial",
                    new TextLayer
                    {
                        Text       = "watermark goodness",
                        FontColor  = ColorTranslator.FromHtml("#" + "ffffff"),
                        FontSize   = 36,
                        Style      = FontStyle.Italic,
                        Opacity    = 80,
                        Position   = new Point(30, 150),
                        DropShadow = true,
                        FontFamily = new FontFamily("arial")
                    }
                },
                {
                    "watermark=watermark goodness&color=fff&fontsize=36&fontstyle=italic&fontopacity=80&textposition=30,150&textshadow=true&fontfamily=arial",
                    new TextLayer
                    {
                        Text       = "watermark goodness",
                        FontColor  = ColorTranslator.FromHtml("#" + "ffffff"),
                        FontSize   = 36,
                        Style      = FontStyle.Italic,
                        Opacity    = 80,
                        Position   = new Point(30, 150),
                        DropShadow = true,
                        FontFamily = new FontFamily("arial")
                    }
                },
                {
                    "watermark=watermark goodness&color=fff&fontsize=36&fontstyle=italic&fontopacity=80&watermark.position=30,150&textshadow=true&fontfamily=arial",
                    new TextLayer
                    {
                        Text       = "watermark goodness",
                        FontColor  = ColorTranslator.FromHtml("#" + "ffffff"),
                        FontSize   = 36,
                        Style      = FontStyle.Italic,
                        Opacity    = 80,
                        Position   = new Point(30, 150),
                        DropShadow = true,
                        FontFamily = new FontFamily("arial")
                    }
                }
            };

            Processors.Watermark watermark = new Processors.Watermark();
            foreach (KeyValuePair <string, TextLayer> item in data)
            {
                watermark.MatchRegexIndex(item.Key);
                TextLayer result = watermark.Processor.DynamicParameter;
                Assert.AreEqual(item.Value, result);
            }
        }
Exemple #14
0
        public void TextDataTest()
        {
            var input = new TextLayer
            {
                Text = "Text"
            };

            var serializer = new TextLayerHandler();
            var output     = (TextLayer)serializer.Reserialize(input);

            Assert.That(output.Text, Is.EqualTo(input.Text));
        }
Exemple #15
0
        XElement FromTextLayer(TextLayer layer)
        {
            return(new XElement("Text", GetContents()));

            IEnumerable <XObject> GetContents()
            {
                foreach (var item in GetLayerContents(layer))
                {
                    yield return(item);
                }
            }
        }
        /// <summary>
        /// Adds a text based watermark to the current image.
        /// </summary>
        /// <param name="textLayer">
        /// The <see cref="T:ImageProcessor.Imaging.TextLayer"/> containing the properties necessary to add
        /// the text based watermark to the image.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public ImageFactory Watermark(TextLayer textLayer)
        {
            if (this.ShouldProcess)
            {
                Watermark watermark = new Watermark {
                    DynamicParameter = textLayer
                };
                this.CurrentImageFormat.ApplyProcessor(watermark.ProcessImage, this);
            }

            return(this);
        }
Exemple #17
0
        public override TextLayer[] Process(TextInfo text)
        {
            TextLayer[] result = null;
            if (text != null)
            {
                result = new TextLayer[1];
                int charCount = text.Text.Length;
                result[0] = new TextLayer(_outputLayers[0], new BaseTextLayerItem[] { new MyLayerItem("Created by " + _name, charCount) });
            }

            return(result);
        }
Exemple #18
0
        /// <summary>
        /// Changes the saturation of the current image.
        /// </summary>
        /// <param name="percentage">
        /// The percentage by which to alter the images saturation.
        /// Any integer between -100 and 100.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        //public ImageFactory Saturation(int percentage)
        //{
        //    if (this.ShouldProcess)
        //    {
        //        // Sanitize the input.
        //        if (percentage > 100 || percentage < -100)
        //        {
        //            percentage = 0;
        //        }

        //        Saturation saturate = new Saturation { DynamicParameter = percentage };

        //        this.Image = saturate.ProcessImage(this);
        //    }

        //    return this;
        //}

        /// <summary>
        /// Adds a vignette image effect to the current image.
        /// </summary>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        //public ImageFactory Vignette()
        //{
        //    if (this.ShouldProcess)
        //    {
        //        Vignette vignette = new Vignette();

        //        this.Image = vignette.ProcessImage(this);
        //    }

        //    return this;
        //}

        /// <summary>
        /// Adds a text based watermark to the current image.
        /// </summary>
        /// <param name="textLayer">
        /// The <see cref="T:ImageProcessor.Imaging.TextLayer"/> containing the properties necessary to add
        /// the text based watermark to the image.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public ImageFactory Watermark(TextLayer textLayer)
        {
            if (this.ShouldProcess)
            {
                Watermark watermark = new Watermark {
                    DynamicParameter = textLayer
                };

                this.Image = watermark.ProcessImage(this);
            }

            return(this);
        }
        public void TestTransformationLayersDeepClone()
        {
            // layers should be cloned
            var layer          = new TextLayer("Hello").FontSize(10).FontFamily("Arial");
            var transformation = new Transformation().Overlay(layer);

            var clone = transformation.Clone();

            layer.FontSize(20);

            Assert.AreEqual(transformation.Generate(), "l_text:Arial_20:Hello");
            Assert.AreEqual(clone.Generate(), "l_text:Arial_10:Hello");
        }
Exemple #20
0
        public override TextLayer[] Process(TextInfo text)
        {
            TextLayer[] result = null;
            if (text != null)
            {
                result = new TextLayer[1];
                int         charCount = text.Text.Length;
                MyLayerItem data      = text.GetLayer("FirstLayer").ItemList[0] as MyLayerItem;
                result[0] = new TextLayer(_outputLayers[0], new BaseTextLayerItem[] { new MyLayerItem("Created by " + _name + " from " + data.Owner.Name, charCount) });
            }

            return(result);
        }
Exemple #21
0
        public async Task <bool> TransparentWatermarkWithCustomTextAsync(string filePath, string text)
        {
            var textLayer = new TextLayer
            {
                Text      = text,
                FontColor = Color.Transparent
            };

            var imageFactory = new ImageFactory(true);

            imageFactory.Load(filePath).Watermark(textLayer).Save(filePath);

            return(true);
        }
Exemple #22
0
        public async Task <bool> TranparentWatermarkAsync(string filePath)
        {
            var textLayer = new TextLayer
            {
                Text      = "Novinak",
                FontColor = Color.Transparent
            };

            var imageFactory = new ImageFactory(true);

            imageFactory.Load(filePath).Watermark(textLayer).Save(filePath);

            return(true);
        }
Exemple #23
0
 protected override void OnRegistered()
 {
     base.OnRegistered();
     TextLayer.AddObject(ModeText);
     TextLayer.AddObject(ExplainText);
     if (!IsStageMaking)
     {
         SelectedTexture.Dispose();
     }
     UILayer = new asd.Layer2D();
     AddLayer(UILayer);
     UILayer.AddObject(SelectedTexture);
     LoadExcelFile();
 }
Exemple #24
0
        public void SetText(string text, int size, Point position, Color color)
        {
            TextLayer textLayer = new TextLayer();

            textLayer.Text       = text;
            textLayer.FontColor  = color;
            textLayer.FontFamily = new FontFamily("나눔스퀘어 Light");
            textLayer.FontSize   = size;
            textLayer.Style      = FontStyle.Regular;
            textLayer.Opacity    = 100;
            textLayer.Position   = position;
            textLayer.DropShadow = false;

            _mainImageFactory.Watermark(textLayer);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_PSD();

            //ExStart:RenderingOfDifferentStylesInOneTextLayer
            //ExSummary:The following example demonstrates how you can render different styles in one text layer in Aspose.PSD
            string sourceFile = dataDir + "text212.psd";
            string outputFile = dataDir + "Output_text212.psd";

            using (var img = (PsdImage)Image.Load(sourceFile))
            {
                TextLayer      textLayer        = (TextLayer)img.Layers[1];
                IText          textData         = textLayer.TextData;
                ITextStyle     defaultStyle     = textData.ProducePortion().Style;
                ITextParagraph defaultParagraph = textData.ProducePortion().Paragraph;
                defaultStyle.FillColor = Color.DimGray;
                defaultStyle.FontSize  = 51;

                textData.Items[1].Style.Strikethrough = true;

                ITextPortion[] newPortions = textData.ProducePortions(
                    new string[]
                {
                    "E=mc", "2\r", "Bold", "Italic\r",
                    "Lowercasetext"
                },
                    defaultStyle,
                    defaultParagraph);

                newPortions[0].Style.Underline     = true;                     // edit text style "E=mc"
                newPortions[1].Style.FontBaseline  = FontBaseline.Superscript; // edit text style "2\r"
                newPortions[2].Style.FauxBold      = true;                     // edit text style "Bold"
                newPortions[3].Style.FauxItalic    = true;                     // edit text style "Italic\r"
                newPortions[3].Style.BaselineShift = -25;                      // edit text style "Italic\r"
                newPortions[4].Style.FontCaps      = FontCaps.SmallCaps;       // edit text style "Lowercasetext"

                foreach (var newPortion in newPortions)
                {
                    textData.AddPortion(newPortion);
                }

                textData.UpdateLayerData();
                img.Save(outputFile);
            }

            //ExEnd:RenderingOfDifferentStylesInOneTextLayer
        }
Exemple #26
0
        public void update_layer_1p()
        {
            long score;

            if (this.Game.current_player() == null)
            {
                score = 0; // Small hack to make something show up on startup
            }
            else
            {
                score = this.Game.current_player().score;
            }

            TextLayer layer = new TextLayer(128 / 2, 5, this.font_for_score_single(score), FontJustify.Center);

            layer.set_text(this.format_score(score));
            ((ScoreLayer)this.layer).layers.Add(layer);
        }
        public void TestWaterMarkRegex()
        {
            Dictionary <string, TextLayer> data = new Dictionary <string, TextLayer>
            {
                {
                    "watermark=watermark goodness&color=fff&fontsize=36&fontstyle=italic&fontopacity=80&textposition=30,150&dropshadow=true&fontfamily=arial",
                    new TextLayer
                    {
                        Text       = "watermark goodness",
                        FontColor  = ColorTranslator.FromHtml("#" + "ffffff"),
                        FontSize   = 36,
                        Style      = FontStyle.Italic,
                        Opacity    = 80,
                        Position   = new Point(30, 150),
                        DropShadow = true,
                        FontFamily = new FontFamily("arial")
                    }
                },
                {
                    "watermark=لا أحد يحب الألم بذاته، يسعى ورائه أو يبتغيه، ببساطة لأنه الألم&color=fff&fontsize=36&fontstyle=italic&fontopacity=80&textposition=30,150&dropshadow=true&fontfamily=arial&vertical=true&rtl=true",
                    new TextLayer
                    {
                        Text        = "لا أحد يحب الألم بذاته، يسعى ورائه أو يبتغيه، ببساطة لأنه الألم",
                        FontColor   = ColorTranslator.FromHtml("#" + "ffffff"),
                        FontSize    = 36,
                        Style       = FontStyle.Italic,
                        Opacity     = 80,
                        Position    = new Point(30, 150),
                        DropShadow  = true,
                        FontFamily  = new FontFamily("arial"),
                        Vertical    = true,
                        RightToLeft = true
                    }
                }
            };

            Processors.Watermark watermark = new Processors.Watermark();
            foreach (KeyValuePair <string, TextLayer> item in data)
            {
                watermark.MatchRegexIndex(item.Key);
                TextLayer result = watermark.Processor.DynamicParameter;
                Assert.AreEqual(item.Value, result);
            }
        }
Exemple #28
0
        /// <summary>
        /// Returns the correct flags for the given text layer.
        /// </summary>
        /// <param name="textLayer">
        /// The <see cref="TextLayer"/> to return the flags for.
        /// </param>
        /// <returns>
        /// The <see cref="StringFormatFlags"/>.
        /// </returns>
        private StringFormatFlags?GetFlags(TextLayer textLayer)
        {
            if (textLayer.Vertical && textLayer.RightToLeft)
            {
                return(StringFormatFlags.DirectionVertical | StringFormatFlags.DirectionRightToLeft);
            }

            if (textLayer.Vertical)
            {
                return(StringFormatFlags.DirectionVertical);
            }

            if (textLayer.RightToLeft)
            {
                return(StringFormatFlags.DirectionRightToLeft);
            }

            return(null);
        }
Exemple #29
0
        void OnDocumentChanged(TextLayer textLayer)
        {
            // remove existing highlighter, if any exists
            textLayer.Services.RemoveService(typeof(IHighlighter));
            textLayer.Services.RemoveService(typeof(DocumentHighlighter));

            TextDocument document = textLayer.Document;

            if (document != null)
            {
                IHighlighter highlighter = CreateHighlighter(textLayer, document);
                textLayer.Services.AddService(typeof(IHighlighter), highlighter);
                // for backward compatiblity, we're registering using both the interface and concrete types
                if (highlighter is DocumentHighlighter)
                {
                    textLayer.Services.AddService(typeof(DocumentHighlighter), highlighter);
                }
            }
        }
    void OnEnable()
    {
        TextLayer comp = target as TextLayer;

        panel = comp.GetComponentInParent <UIPanel>();
#if TEXTMESH_PRO
        text = comp.GetComponentsInChildren <TextMeshPro>();
#endif
        if (panel.drawCalls != null)
        {
            foreach (UIDrawCall dc in panel.drawCalls)
            {
                if (dc != null && dc.GetComponent <Renderer>() != null)
                {
                    sortingLayerId = Math.Max(sortingLayerId, dc.GetComponent <Renderer>().sortingLayerID);
                }
            }
        }
    }
Exemple #31
0
        public static void Display(User user, DiscordClient client)
        {
            byte[] avatar = null;
            using (var wc = new System.Net.WebClient()) {
                avatar = (user.AvatarUrl == null) ? null : wc.DownloadData(user.AvatarUrl);
                if (avatar == null)
                {
                    client.GetChannel(
                        (from channel in Config.INSTANCE.primaryChannels where channel.server_id == user.Server.Id select channel.channel_id).First()
                        ).SendMessage("Welcome new comrade" + user.Mention);

                    return;
                }
            }
            var   astream   = new MemoryStream(avatar);
            Image ai        = Image.FromStream(astream);
            var   outstream = new MemoryStream();

            using (var ifact = new ImageProcessor.ImageFactory()) {
                //159,204 image size 283x283
                ImageLayer ilay = new ImageLayer()
                {
                    Image    = ai,
                    Size     = new Size(283, 283),
                    Position = new Point(159, 204)
                };
                ifact.Load("resources/welcome.jpg");
                ifact.Overlay(ilay);
                System.Drawing.Color yellow = System.Drawing.Color.FromArgb(208, 190, 25);
                TextLayer            uname  = new TextLayer()
                {
                    Position = new Point(108, 512), FontFamily = FontFamily.GenericSansSerif, FontSize = 30, Text = user.Nickname, FontColor = yellow
                };
                ifact.Watermark(uname);
                ifact.Save(outstream);
            }
            Channel general = client.GetChannel((from channel in Config.INSTANCE.primaryChannels where channel.server_id == user.Server.Id select channel.channel_id).First());

            general.SendMessage("Welcome new comrade " + user.Mention);
            general.SendFile("welcome.jpg", outstream);
            ModerationLog.LogToPublic($"User {user} joined.", client.GetServer(user.Server.Id));
        }
Exemple #32
0
#pragma warning restore 0169

		public WpfHexViewImpl(HexBuffer buffer, VSTE.ITextViewRoleSet roles, VSTE.IEditorOptions parentOptions, HexEditorOptionsFactoryService hexEditorOptionsFactoryService, ICommandService commandService, FormattedHexSourceFactoryService formattedHexSourceFactoryService, HexViewClassifierAggregatorService hexViewClassifierAggregatorService, HexAndAdornmentSequencerFactoryService hexAndAdornmentSequencerFactoryService, HexBufferLineFormatterFactoryService bufferLineProviderFactoryService, HexClassificationFormatMapService classificationFormatMapService, HexEditorFormatMapService editorFormatMapService, HexAdornmentLayerDefinitionService adornmentLayerDefinitionService, HexLineTransformProviderService lineTransformProviderService, HexSpaceReservationStackProvider spaceReservationStackProvider, Lazy<WpfHexViewCreationListener, IDeferrableTextViewRoleMetadata>[] wpfHexViewCreationListeners, VSTC.IClassificationTypeRegistryService classificationTypeRegistryService, Lazy<HexCursorProviderFactory, ITextViewRoleMetadata>[] hexCursorProviderFactories) {
			if (buffer == null)
				throw new ArgumentNullException(nameof(buffer));
			if (roles == null)
				throw new ArgumentNullException(nameof(roles));
			if (parentOptions == null)
				throw new ArgumentNullException(nameof(parentOptions));
			if (hexEditorOptionsFactoryService == null)
				throw new ArgumentNullException(nameof(hexEditorOptionsFactoryService));
			if (commandService == null)
				throw new ArgumentNullException(nameof(commandService));
			if (formattedHexSourceFactoryService == null)
				throw new ArgumentNullException(nameof(formattedHexSourceFactoryService));
			if (hexViewClassifierAggregatorService == null)
				throw new ArgumentNullException(nameof(hexViewClassifierAggregatorService));
			if (hexAndAdornmentSequencerFactoryService == null)
				throw new ArgumentNullException(nameof(hexAndAdornmentSequencerFactoryService));
			if (bufferLineProviderFactoryService == null)
				throw new ArgumentNullException(nameof(bufferLineProviderFactoryService));
			if (classificationFormatMapService == null)
				throw new ArgumentNullException(nameof(classificationFormatMapService));
			if (editorFormatMapService == null)
				throw new ArgumentNullException(nameof(editorFormatMapService));
			if (adornmentLayerDefinitionService == null)
				throw new ArgumentNullException(nameof(adornmentLayerDefinitionService));
			if (lineTransformProviderService == null)
				throw new ArgumentNullException(nameof(lineTransformProviderService));
			if (spaceReservationStackProvider == null)
				throw new ArgumentNullException(nameof(spaceReservationStackProvider));
			if (wpfHexViewCreationListeners == null)
				throw new ArgumentNullException(nameof(wpfHexViewCreationListeners));
			if (classificationTypeRegistryService == null)
				throw new ArgumentNullException(nameof(classificationTypeRegistryService));
			if (hexCursorProviderFactories == null)
				throw new ArgumentNullException(nameof(hexCursorProviderFactories));
			canvas = new HexViewCanvas(this);
			Buffer = buffer;
			thisHexLineTransformSource = new MyHexLineTransformSource(this);
			this.bufferLineProviderFactoryService = bufferLineProviderFactoryService;
			mouseHoverHelper = new MouseHoverHelper(this);
			physicalLineCache = new PhysicalLineCache(32);
			visiblePhysicalLines = new List<PhysicalLine>();
			invalidatedRegions = new List<HexBufferSpan>();
			this.formattedHexSourceFactoryService = formattedHexSourceFactoryService;
			zoomLevel = VSTE.ZoomConstants.DefaultZoom;
			DsImage.SetZoom(VisualElement, zoomLevel / 100);
			this.adornmentLayerDefinitionService = adornmentLayerDefinitionService;
			this.lineTransformProviderService = lineTransformProviderService;
			this.wpfHexViewCreationListeners = wpfHexViewCreationListeners.Where(a => roles.ContainsAny(a.Metadata.TextViewRoles)).ToArray();
			recreateLineTransformProvider = true;
			normalAdornmentLayerCollection = new HexAdornmentLayerCollection(this, HexLayerKind.Normal);
			overlayAdornmentLayerCollection = new HexAdornmentLayerCollection(this, HexLayerKind.Overlay);
			underlayAdornmentLayerCollection = new HexAdornmentLayerCollection(this, HexLayerKind.Underlay);
			canvas.IsVisibleChanged += WpfHexView_IsVisibleChanged;
			Roles = roles;
			Options = hexEditorOptionsFactoryService.GetOptions(this);
			Options.Parent = parentOptions;
			ViewScroller = new HexViewScrollerImpl(this);
			hasKeyboardFocus = canvas.IsKeyboardFocusWithin;
			oldViewState = new HexViewState(this);
			aggregateClassifier = hexViewClassifierAggregatorService.GetClassifier(this);
			hexAndAdornmentSequencer = hexAndAdornmentSequencerFactoryService.Create(this);
			classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(this);
			editorFormatMap = editorFormatMapService.GetEditorFormatMap(this);
			spaceReservationStack = spaceReservationStackProvider.Create(this);

			textLayer = new TextLayer(GetAdornmentLayer(PredefinedHexAdornmentLayers.Text));
			HexSelection = new HexSelectionImpl(this, GetAdornmentLayer(PredefinedHexAdornmentLayers.Selection), editorFormatMap);
			HexCaret = new HexCaretImpl(this, GetAdornmentLayer(PredefinedHexAdornmentLayers.Caret), classificationFormatMap, classificationTypeRegistryService);

			canvas.Children.Add(underlayAdornmentLayerCollection);
			canvas.Children.Add(normalAdornmentLayerCollection);
			canvas.Children.Add(overlayAdornmentLayerCollection);
			canvas.Focusable = true;
			canvas.FocusVisualStyle = null;
			InitializeOptions();

			Options.OptionChanged += EditorOptions_OptionChanged;
			Buffer.ChangedLowPriority += HexBuffer_ChangedLowPriority;
			Buffer.BufferSpanInvalidated += Buffer_BufferSpanInvalidated;
			aggregateClassifier.ClassificationChanged += AggregateClassifier_ClassificationChanged;
			hexAndAdornmentSequencer.SequenceChanged += HexAndAdornmentSequencer_SequenceChanged;
			classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
			editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;
			spaceReservationStack.GotAggregateFocus += SpaceReservationStack_GotAggregateFocus;
			spaceReservationStack.LostAggregateFocus += SpaceReservationStack_LostAggregateFocus;

			UpdateBackground();
			CreateFormattedLineSource(ViewportWidth);
			var dummy = BufferLines;
			HexSelection.Initialize();
			HexCaret.Initialize();
			InitializeZoom();
			UpdateRemoveExtraTextLineVerticalPixels();

			if (Roles.Contains(PredefinedHexViewRoles.Interactive))
				RegisteredCommandElement = commandService.Register(VisualElement, this);
			else
				RegisteredCommandElement = TE.NullRegisteredCommandElement.Instance;

			hexCursorProviderInfoCollection = new HexCursorProviderInfoCollection(CreateCursorProviders(hexCursorProviderFactories), Cursors.IBeam);
			hexCursorProviderInfoCollection.CursorChanged += HexCursorProviderInfoCollection_CursorChanged;
			canvas.Cursor = hexCursorProviderInfoCollection.Cursor;

			NotifyHexViewCreated();
		}