OSDN Git Service

DPIの設定を変えると変換窓がずれる現象を修正した
authorkonekoneko <test2214@hotmail.co.jp>
Sat, 11 Apr 2015 10:42:33 +0000 (19:42 +0900)
committerkonekoneko <test2214@hotmail.co.jp>
Sat, 11 Apr 2015 10:42:33 +0000 (19:42 +0900)
Common/DotNetTextStore/TextStoreBase.cs
Common/ITextRender.cs
Metro/FooEditEngine/FooTextBox.cs
WPF/FooEditEngine/FooTextBox.cs

index 90e8c6d..b64def7 100644 (file)
@@ -94,9 +94,6 @@ namespace DotNetTextStore
 \r
     public abstract class TextStoreBase\r
     {\r
-        public delegate double GetDpiHandeler();\r
-        public event GetDpiHandeler GetDpi;\r
-\r
         public delegate bool IsReadOnlyHandler();\r
         public event IsReadOnlyHandler IsReadOnly;\r
 \r
@@ -1242,15 +1239,10 @@ namespace DotNetTextStore
                 var pointBotttomRight = new POINT();\r
                 GetStringExtent(i_startIndex, i_endIndex, out pointTopLeft, out pointBotttomRight);\r
 \r
-                if(this.GetDpi == null)\r
-                    throw new NotImplementedException();\r
-\r
-                double dpi = this.GetDpi();\r
-\r
-                o_rect.left = (int)(pointTopLeft.x * dpi / 96.0);\r
-                o_rect.top = (int)(pointTopLeft.y * dpi / 96.0);\r
-                o_rect.bottom = (int)(pointBotttomRight.y * dpi / 96.0);\r
-                o_rect.right = (int)(pointBotttomRight.x * dpi / 96.0);\r
+                o_rect.left = (int)(pointTopLeft.x);\r
+                o_rect.top = (int)(pointTopLeft.y);\r
+                o_rect.bottom = (int)(pointBotttomRight.y);\r
+                o_rect.right = (int)(pointBotttomRight.x);\r
                 o_isClipped = false;\r
 #if TSF_DEBUG_OUTPUT\r
                 DebugOut.Print("rect left:{0} top:{1} bottom:{2} right:{3}", o_rect.left, o_rect.top, o_rect.bottom, o_rect.right);\r
@@ -1271,15 +1263,10 @@ namespace DotNetTextStore
 \r
                 GetScreenExtent(out pointTopLeft, out pointBottomRight);\r
 \r
-                if (this.GetDpi == null)\r
-                    throw new NotImplementedException();\r
-\r
-                double dpi = this.GetDpi();\r
-\r
-                o_rect.left = (int)(pointTopLeft.x * dpi / 96.0);\r
-                o_rect.top = (int)(pointTopLeft.y * dpi / 96.0);\r
-                o_rect.bottom = (int)(pointBottomRight.y * dpi / 96.0);\r
-                o_rect.right = (int)(pointBottomRight.x * dpi / 96.0);\r
+                o_rect.left = (int)(pointTopLeft.x);\r
+                o_rect.top = (int)(pointTopLeft.y);\r
+                o_rect.bottom = (int)(pointBottomRight.y);\r
+                o_rect.right = (int)(pointBottomRight.x);\r
 #if TSF_DEBUG_OUTPUT\r
                 DebugOut.Print("rect left:{0} top:{1} bottom:{2} right:{3}", o_rect.left, o_rect.top, o_rect.bottom, o_rect.right);\r
 #endif\r
index a93be4e..a48d42d 100644 (file)
@@ -65,6 +65,13 @@ namespace FooEditEngine
             result ^= this.Y.GetHashCode();\r
             return result;\r
         }\r
+\r
+        public Point Scale(double scale)\r
+        {\r
+            this.X *= scale;\r
+            this.Y *= scale;\r
+            return this;\r
+        }\r
 #if WINFORM\r
         public static implicit operator Point(System.Drawing.Point p)\r
         {\r
index 79ca99b..14d71ad 100644 (file)
@@ -60,7 +60,6 @@ namespace FooEditEngine.Metro
             this.textStore = new TextStore2();\r
             this.textStore.IsLoading += textStore_IsLoading;\r
             this.textStore.IsReadOnly += textStore_IsReadOnly;\r
-            this.textStore.GetDpi += textStore_GetDpi;\r
             this.textStore.GetStringLength += () => this.Document.Length;\r
             this.textStore.GetString += _textStore_GetString;\r
             this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;\r
@@ -669,13 +668,6 @@ namespace FooEditEngine.Metro
             this.Refresh();\r
         }\r
 \r
-        double textStore_GetDpi()\r
-        {\r
-            float dpi;\r
-            this.Render.GetDpi(out dpi, out dpi);\r
-            return dpi;\r
-        }\r
-\r
         bool textStore_IsReadOnly()\r
         {\r
             return false;\r
@@ -717,9 +709,13 @@ namespace FooEditEngine.Metro
             Point startPos, endPos;\r
             TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);\r
 \r
+            float dpi;\r
+            this.Render.GetDpi(out dpi, out dpi);\r
+            double scale = dpi / 96.0;\r
+\r
             var gt = this.TransformToVisual(Window.Current.Content);\r
-            startPos = gt.TransformPoint(startPos);\r
-            endPos = gt.TransformPoint(endPos);\r
+            startPos = gt.TransformPoint(startPos.Scale(scale));\r
+            endPos = gt.TransformPoint(endPos.Scale(scale));\r
 \r
             o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);\r
             o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);\r
index c683721..f25a695 100644 (file)
@@ -73,7 +73,6 @@ namespace FooEditEngine.WPF
             this.textStore = new TextStore();\r
             this.textStore.IsLoading += textStore_IsLoading;\r
             this.textStore.IsReadOnly += textStore_IsReadOnly;\r
-            this.textStore.GetDpi += textStore_GetDpi;\r
             this.textStore.GetStringLength += () => this.Document.Length;\r
             this.textStore.GetString += _textStore_GetString;\r
             this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;\r
@@ -541,13 +540,6 @@ namespace FooEditEngine.WPF
             get { return this.textStore; }\r
         }\r
 \r
-        double textStore_GetDpi()\r
-        {\r
-            float dpi;\r
-            this.Render.GetDpi(out dpi, out dpi);\r
-            return dpi;\r
-        }\r
-\r
         bool textStore_IsReadOnly()\r
         {\r
             return false;\r
@@ -601,8 +593,12 @@ namespace FooEditEngine.WPF
             Point startPos, endPos;\r
             TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);\r
 \r
-            startPos = PointToScreen(this.TranslatePoint(startPos, this));\r
-            endPos = PointToScreen(this.TranslatePoint(endPos, this));\r
+            float dpi;\r
+            this.Render.GetDpi(out dpi, out dpi);\r
+            double scale = dpi / 96.0;\r
+            \r
+            startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));\r
+            endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));\r
             \r
             o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);\r
             o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);\r