<commit_before>/////////////////////////////////////////////////////////////////////////////////
// Paint.NET                                                                   //
// Copyright (C) dotPDN LLC, <NAME>, <NAME>, and contributors.     //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved.          //
// See license-pdn.txt for full licensing and attribution details.             //
//                                                                             //
// Ported to Pinta by: <NAME> <<EMAIL>>                 //
//                     <NAME> <<EMAIL>>                      //
/////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using Gdk;
using Gtk;
using Mono.Unix;
using Pinta.Core;

namespace Pinta.Tools
{
	public class TextTool : BaseTool
	{
		// Variables for dragging
		private Cairo.PointD startMouseXY;
		private Point startClickPoint;
		private bool tracking;
		private Gdk.Cursor cursor_hand;

		private Point clickPoint;
		private bool is_editing;
		private Rectangle old_cursor_bounds = Rectangle.Zero;

		//This is used to temporarily store the UserLayer's and TextLayer's previous ImageSurface states.
		private Cairo.ImageSurface text_undo_surface;
		private Cairo.ImageSurface user_undo_surface;
		private TextEngine undo_engine;

		private Rectangle CurrentTextBounds
		{
			get
			{
				return PintaCore.Workspace.ActiveDocument.CurrentUserLayer.textBounds;
			}

			set
			{
				PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.textBounds;

				PintaCore.Workspace.ActiveDocument.CurrentUserLayer.textBounds = value;
			}
		}

		private TextEngine CurrentTextEngine
		{
			get
			{
				return PintaCore.Workspace.HasOpenDocuments ?
					PintaCore.Workspace.ActiveDocument.CurrentUserLayer.tEngine : null;
			}

			set
			{
				PintaCore.Workspace.ActiveDocument.CurrentUserLayer.tEngine = value;
			}
		}

		//While this is true, text will not be finalized upon Surface.Clone calls.
		private bool ignoreCloneFinalizations = false;

		//Whether or not either (or both) of the Ctrl keys are pressed.
		private bool ctrlKey = false;

		//Store the most recent mouse position.
		private Point lastMousePosition = new Point(0, 0);

		//Whether or not the previous TextTool mouse cursor shown was the normal one.
		private bool previousMouseCursorNormal = true;

		public override string Name { get { return Catalog.GetString ("Text"); } }
		private string FinalizeName { get { return Catalog.GetString("Text - Finalize"); } }
		public override string Icon { get { return "Tools.Text.png"; } }
		public override Gdk.Key ShortcutKey { get { return Gdk.Key.T; } }
		public override int Priority { get { return 37; } }

		public override string StatusBarText {
			get { return Catalog.GetString ("Left click to place cursor, then type desired text. Text color is primary color."); }
		}

		public override Gdk.Cursor DefaultCursor { get { return new Gdk.Cursor (PintaCore.Chrome.Canvas.Display, PintaCore.Resources.GetIcon("Cursor.Text.png"), 16, 8);	} }
		public Gdk.Cursor InvalidEditCursor { get { return new Gdk.Cursor(PintaCore.Chrome.Canvas.Display, PintaCore.Resources.GetIcon("Menu.Edit.EraseSelection.png"), 8, 0); } }

		#region Constructor
		public TextTool ()
		{
			cursor_hand = new Gdk.Cursor (PintaCore.Chrome.Canvas.Display, PintaCore.Resources.GetIcon ("Cursor.Pan.png"), 8, 8);
		}

		static TextTool ()
		{
			Gtk.IconFactory fact = new Gtk.IconFactory ();
			fact.Add ("ShapeTool.Outline.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("ShapeTool.Outline.png")));
			fact.Add ("ShapeTool.Fill.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("ShapeTool.Fill.png")));
			fact.Add ("ShapeTool.OutlineFill.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("ShapeTool.OutlineFill.png")));
			fact.Add ("TextTool.FillBackground.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("TextTool.FillBackground.png")));
			fact.AddDefault ();
		}
		#endregion

		#region ToolBar
		private ToolBarLabel font_label;
		private ToolBarFontComboBox font_combo;
		private ToolBarComboBox size_combo;
		private ToolBarToggleButton bold_btn;
		private ToolBarToggleButton italic_btn;<commit_msg>[Fixes bug #1190864] Correct the hotspot of the text cursor.<commit_after>/////////////////////////////////////////////////////////////////////////////////
// Paint.NET                                                                   //
// Copyright (C) dotPDN LLC, <NAME>, <NAME>, and contributors.     //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved.          //
// See license-pdn.txt for full licensing and attribution details.             //
//                                                                             //
// Ported to Pinta by: <NAME> <<EMAIL>>                 //
//                     <NAME> <<EMAIL>>                      //
/////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using Gdk;
using Gtk;
using Mono.Unix;
using Pinta.Core;

namespace Pinta.Tools
{
	public class TextTool : BaseTool
	{
		// Variables for dragging
		private Cairo.PointD startMouseXY;
		private Point startClickPoint;
		private bool tracking;
		private Gdk.Cursor cursor_hand;

		private Point clickPoint;
		private bool is_editing;
		private Rectangle old_cursor_bounds = Rectangle.Zero;

		//This is used to temporarily store the UserLayer's and TextLayer's previous ImageSurface states.
		private Cairo.ImageSurface text_undo_surface;
		private Cairo.ImageSurface user_undo_surface;
		private TextEngine undo_engine;

		private Rectangle CurrentTextBounds
		{
			get
			{
				return PintaCore.Workspace.ActiveDocument.CurrentUserLayer.textBounds;
			}

			set
			{
				PintaCore.Workspace.ActiveDocument.CurrentUserLayer.previousTextBounds = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.textBounds;

				PintaCore.Workspace.ActiveDocument.CurrentUserLayer.textBounds = value;
			}
		}

		private TextEngine CurrentTextEngine
		{
			get
			{
				return PintaCore.Workspace.HasOpenDocuments ?
					PintaCore.Workspace.ActiveDocument.CurrentUserLayer.tEngine : null;
			}

			set
			{
				PintaCore.Workspace.ActiveDocument.CurrentUserLayer.tEngine = value;
			}
		}

		//While this is true, text will not be finalized upon Surface.Clone calls.
		private bool ignoreCloneFinalizations = false;

		//Whether or not either (or both) of the Ctrl keys are pressed.
		private bool ctrlKey = false;

		//Store the most recent mouse position.
		private Point lastMousePosition = new Point(0, 0);

		//Whether or not the previous TextTool mouse cursor shown was the normal one.
		private bool previousMouseCursorNormal = true;

		public override string Name { get { return Catalog.GetString ("Text"); } }
		private string FinalizeName { get { return Catalog.GetString("Text - Finalize"); } }
		public override string Icon { get { return "Tools.Text.png"; } }
		public override Gdk.Key ShortcutKey { get { return Gdk.Key.T; } }
		public override int Priority { get { return 37; } }

		public override string StatusBarText {
			get { return Catalog.GetString ("Left click to place cursor, then type desired text. Text color is primary color."); }
		}

		public override Gdk.Cursor DefaultCursor {
			get {
				return new Gdk.Cursor (PintaCore.Chrome.Canvas.Display,
				                       PintaCore.Resources.GetIcon ("Cursor.Text.png"),
				                       16, 16);
			}
		}
		public Gdk.Cursor InvalidEditCursor { get { return new Gdk.Cursor(PintaCore.Chrome.Canvas.Display, PintaCore.Resources.GetIcon("Menu.Edit.EraseSelection.png"), 8, 0); } }

		#region Constructor
		public TextTool ()
		{
			cursor_hand = new Gdk.Cursor (PintaCore.Chrome.Canvas.Display, PintaCore.Resources.GetIcon ("Cursor.Pan.png"), 8, 8);
		}

		static TextTool ()
		{
			Gtk.IconFactory fact = new Gtk.IconFactory ();
			fact.Add ("ShapeTool.Outline.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("ShapeTool.Outline.png")));
			fact.Add ("ShapeTool.Fill.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("ShapeTool.Fill.png")));
			fact.Add ("ShapeTool.OutlineFill.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("ShapeTool.OutlineFill.png")));
			fact.Add ("TextTool.FillBackground.png", new Gtk.IconSet (PintaCore.Resources.GetIcon ("TextTool.FillBackground.png")));
			fact.AddDefault ();
		}
		#endregion

		#region ToolBar
		private ToolBarLabel font_label;
		private ToolBarFontComboBox font_combo;
		private ToolBarComboBox size_combo;
		private ToolBarToggleButton bold_btn;
		private ToolBarToggleButton italic_btn;
{'fraction_non_alphanumeric': 0.12944539736992566, 'fraction_numerical': 0.003430531732418525, 'mean_word_length': 2.6563545150501673, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6174417', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2377, 'n_words': 653}