/// <summary>
        ///
        /// </summary>
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            base.OnKeyPress(e);

            if (!CharUtil.CanDraw(e.KeyChar))
            {
                return;
            }

            e.Handled = true;
            var isFirstAppend = _inputBuffer.Length == 0;

            _inputBuffer.Append(e.KeyChar);

            // 日本語入力の場合に1文字毎に当該イベントが発生するが、一連の文字列として処理する為の処置
            // やや強引だが、とりあえずこの方法にしておく(正しく処理するにはIMM関連のWin32APIレベルでの対応が必要で面倒なので)
            if (isFirstAppend)
            {
                BeginInvoke((Action)(() =>
                {
                    _presenter.InsertText(_inputBuffer.ToString());
                    _inputBuffer.Clear();
                }));
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        private CharSize InternalMeasureChar(char ch)
        {
            Debug.Assert(CharUtil.CanDraw(ch));

            var size = _jsFont.Call <JsonElement>("measureChar", ch);

            return(new CharSize(
                       size.GetProperty("width").GetDouble(),
                       size.GetProperty("height").GetDouble()));
        }
Esempio n. 3
0
        private CharSize InternalMeasureChar(char ch)
        {
            Debug.Assert(CharUtil.CanDraw(ch));

            using (var sf = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic))
            {
                var g = _measureCharOffscreen.Graphics;
                sf.SetMeasurableCharacterRanges(new[] { new System.Drawing.CharacterRange(0, 1) });
                var text    = ch + "a"; // 文字がスペースの場合にサイズが0になってしまうので、その回避
                var regions = g.MeasureCharacterRanges(text, _font, new System.Drawing.RectangleF(0, 0, 1000, 1000), sf);
                System.Drawing.RectangleF rect = regions[0].GetBounds(g);
                return(new CharSize(rect.Width, rect.Height));
            }
        }
        /// <summary>
        /// 文字ループ。
        /// </summary>
        public IEnumerable <ICharMetric> EnumerateCharMetrics(IReadOnlyRegion2D clipRegion)
        {
            foreach (var lineMetric in EnumerateLineMetrics(clipRegion))
            {
                foreach (var charMetric in EnumerateCharMetricsByLine(lineMetric.Index, true, true))
                {
                    Debug.Assert(CharUtil.CanDraw(charMetric.Char));

                    if (clipRegion.IntersectsWith(charMetric.CharRect))
                    {
                        yield return(charMetric);
                    }

                    if (charMetric.Right > clipRegion.Bounds.Right)
                    {
                        break;
                    }
                }
            }
        }