예제 #1
0
        private CachedFont CreateFont(ITextRunProps textRun, string key, byte charset, bool verticalFont, string fontFamily, float fontSize)
        {
            CachedFont cachedFont = new CachedFont();

            this.m_fontDict.Add(key, cachedFont);
            bool bold   = textRun.Bold;
            bool italic = textRun.Italic;

            RPLFormat.TextDecorations textDecoration = textRun.TextDecoration;
            bool lineThrough = textDecoration == RPLFormat.TextDecorations.LineThrough;

            cachedFont.Font = FontCache.CreateGdiPlusFont(fontFamily, textRun.FontSize, ref bold, ref italic, lineThrough, false);
            int num = 0;

            if (this.UseEmSquare)
            {
                int emHeight = cachedFont.Font.FontFamily.GetEmHeight(cachedFont.Font.Style);
                cachedFont.ScaleFactor = (float)emHeight / fontSize;
                num = emHeight;
            }
            else
            {
                num = (int)(fontSize + 0.5);
            }
            cachedFont.Hfont = this.CreateGdiFont(this.m_writingMode, num, bold, italic, lineThrough, charset, verticalFont, cachedFont.Font.FontFamily.Name);
            return(cachedFont);
        }
예제 #2
0
        public static void ExtDrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline)
        {
            uint crColor = 0u;

            try
            {
                uint colorInt = run.ColorInt;
                if (underline != null)
                {
                    underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), colorInt);
                }
                crColor = Win32.SetTextColor(hdc, colorInt);
                CachedFont cachedFont = run.GetCachedFont(hdc, fontCache);
                fontCache.SelectFontObject(hdc, cachedFont.Hfont);
                int[] lpDx      = null;
                uint  fuOptions = 0u;
                if (run.ScriptAnalysis.fRTL == 1)
                {
                    fuOptions = 128u;
                }
                if (!Win32.ExtTextOut(hdc, x, baselineY, fuOptions, IntPtr.Zero, run.Text, (uint)run.Text.Length, lpDx))
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }
            }
            finally
            {
                crColor = Win32.SetTextColor(hdc, crColor);
            }
        }
예제 #3
0
        public static void DrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline)
        {
            uint crColor = 0u;

            try
            {
                uint colorInt = run.ColorInt;
                if (underline != null)
                {
                    underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), colorInt);
                }
                crColor = Win32.SetTextColor(hdc, colorInt);
                GlyphData      glyphData            = run.GetGlyphData(hdc, fontCache);
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                CachedFont     cachedFont           = run.GetCachedFont(hdc, fontCache);
                fontCache.SelectFontObject(hdc, cachedFont.Hfont);
                int num = Win32.ScriptTextOut(hdc, ref cachedFont.ScriptCache, x, baselineY, 4u, IntPtr.Zero, ref run.SCRIPT_ANALYSIS, IntPtr.Zero, 0, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphData.Advances, (int[])null, glyphData.GOffsets);
                if (Win32.Failed(num))
                {
                    Marshal.ThrowExceptionForHR(num);
                }
            }
            finally
            {
                crColor = Win32.SetTextColor(hdc, crColor);
            }
        }
 public TexRunShapeData(TextRun run, bool storeGlyph)
 {
     if (storeGlyph && run.GlyphData != null)
     {
         this.m_glyphData = run.GlyphData.GlyphScriptShapeData;
     }
     this.m_analysis         = run.SCRIPT_ANALYSIS;
     this.m_scriptLogAttr    = run.ScriptLogAttr;
     this.m_cachedFont       = run.CachedFont;
     this.m_runState         = run.State;
     this.m_itemizedScriptId = run.ItemizedScriptId;
 }
예제 #5
0
        public TextRun(string text, TextRun textRun, SCRIPT_LOGATTR[] scriptLogAttr)
            : this(text, textRun)
        {
            this.SCRIPT_ANALYSIS    = textRun.SCRIPT_ANALYSIS;
            this.ScriptLogAttr      = scriptLogAttr;
            this.m_cachedFont       = textRun.CachedFont;
            this.m_itemizedScriptId = textRun.ItemizedScriptId;
            bool hasEastAsianChars = this.HasEastAsianChars;

            this.m_runState        = textRun.State;
            this.HasEastAsianChars = hasEastAsianChars;
        }
예제 #6
0
        public CachedFont GetFont(ITextRunProps textRunProps, byte charset, float fontSize, bool verticalFont)
        {
            string     fontFamily = null;
            float      num        = 0f;
            string     runKey     = this.GetRunKey(textRunProps, out fontFamily, out num);
            string     key        = this.GetKey(runKey, charset, verticalFont, null, fontSize);
            CachedFont result     = null;

            if (!this.m_fontDict.TryGetValue(key, out result))
            {
                return(this.CreateFont(textRunProps, key, charset, verticalFont, fontFamily, fontSize));
            }
            return(result);
        }
예제 #7
0
 public TextRun(string text, ITextRunProps props, TexRunShapeData shapeData)
     : this(text, props)
 {
     if (shapeData != null)
     {
         this.SCRIPT_ANALYSIS    = shapeData.Analysis;
         this.ScriptLogAttr      = shapeData.ScriptLogAttr;
         this.m_cachedFont       = shapeData.Font;
         this.m_itemizedScriptId = shapeData.ItemizedScriptId;
         this.m_runState         = shapeData.State;
         if (shapeData.GlyphData != null)
         {
             this.m_cachedGlyphData = new GlyphData(shapeData.GlyphData);
         }
     }
 }
예제 #8
0
        private CaretInfo MapLocation(Win32DCSafeHandle hdc, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run)
        {
            CaretInfo caretInfo = null;

            run = null;
            int   lineYOffset = default(int);
            int   lineHeight  = default(int);
            int   iCP         = default(int);
            bool  isFirstLine = default(bool);
            bool  isLastLine  = default(bool);
            Point paragraphAndRunCoordinates = this.GetParagraphAndRunCoordinates(hdc, location, moveCaretToNextLine, out lineYOffset, out lineHeight, out run, out iCP, out isFirstLine, out isLastLine);

            if (run != null)
            {
                GlyphData      glyphData            = run.GlyphData;
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                int            num = 0;
                if (glyphData != null && run.CharacterCount > 0)
                {
                    int num2 = Win32.ScriptCPtoX(iCP, false, run.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref run.SCRIPT_ANALYSIS, ref num);
                    if (Win32.Failed(num2))
                    {
                        Marshal.ThrowExceptionForHR(num2);
                    }
                }
                caretInfo = new CaretInfo();
                CachedFont cachedFont = run.GetCachedFont(hdc, this.FontCache);
                caretInfo.Height      = cachedFont.GetHeight(hdc, this.FontCache);
                caretInfo.Ascent      = cachedFont.GetAscent(hdc, this.FontCache);
                caretInfo.Descent     = cachedFont.GetDescent(hdc, this.FontCache);
                caretInfo.LineHeight  = lineHeight;
                caretInfo.LineYOffset = lineYOffset;
                caretInfo.IsFirstLine = isFirstLine;
                caretInfo.IsLastLine  = isLastLine;
                List <Paragraph> rTParagraph = this.RTParagraphs;
                int y = paragraphAndRunCoordinates.Y - caretInfo.Ascent;
                if (relativeToRun)
                {
                    caretInfo.Position = new Point(num, y);
                }
                else
                {
                    caretInfo.Position = new Point(paragraphAndRunCoordinates.X + num, y);
                }
            }
            return(caretInfo);
        }
예제 #9
0
        public CachedFont GetFallbackFont(ITextRunProps textRunProps, byte charset, int script, bool verticalFont)
        {
            string fontFamily = null;
            float  fontSize   = 0f;
            string runKey     = this.GetRunKey(textRunProps, out fontFamily, out fontSize);
            int    index      = 0;

            if (!FontCache.ScriptFontMapping.TryGetValue(script, out index))
            {
                index = 0;
            }
            fontFamily = FontCache.FontFallback[index];
            string     key    = this.GetKey(runKey, charset, verticalFont, fontFamily, null);
            CachedFont result = null;

            if (!this.m_fontDict.TryGetValue(key, out result))
            {
                return(this.CreateFont(textRunProps, key, charset, verticalFont, fontFamily, fontSize));
            }
            return(result);
        }
예제 #10
0
        public static void DrawClippedTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, uint fontColorOverride, Rectangle clipRect, Underline underline)
        {
            uint   crColor = 0u;
            IntPtr intPtr  = IntPtr.Zero;

            try
            {
                if (underline != null)
                {
                    underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), fontColorOverride);
                }
                RECT rECT = default(RECT);
                rECT.left   = clipRect.Left;
                rECT.right  = clipRect.Right;
                rECT.top    = clipRect.Top;
                rECT.bottom = clipRect.Bottom;
                crColor     = Win32.SetTextColor(hdc, fontColorOverride);
                GlyphData      glyphData            = run.GetGlyphData(hdc, fontCache);
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                CachedFont     cachedFont           = run.GetCachedFont(hdc, fontCache);
                fontCache.SelectFontObject(hdc, cachedFont.Hfont);
                intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rECT));
                Marshal.StructureToPtr(rECT, intPtr, false);
                int num = Win32.ScriptTextOut(hdc, ref cachedFont.ScriptCache, x, baselineY, 4u, intPtr, ref run.SCRIPT_ANALYSIS, IntPtr.Zero, 0, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphData.Advances, (int[])null, glyphData.GOffsets);
                if (Win32.Failed(num))
                {
                    Marshal.ThrowExceptionForHR(num);
                }
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr);
                }
                crColor = Win32.SetTextColor(hdc, crColor);
            }
        }
예제 #11
0
        public void ShapeAndPlace(Win32DCSafeHandle hdc, FontCache fontCache)
        {
            bool verticalFont = false;

            if (fontCache.AllowVerticalFont)
            {
                verticalFont = this.HasEastAsianChars;
            }
            if (this.m_cachedFont == null)
            {
                this.m_cachedFont = fontCache.GetFont(this.m_textRunProps, this.GetCharset(), verticalFont);
                this.FallbackFont = false;
            }
            CachedFont cachedFont = this.m_cachedFont;
            bool       flag       = false;
            bool       flag2      = false;
            string     text       = this.m_text;
            int        num        = Convert.ToInt32((double)text.Length * 1.5 + 16.0);

            this.m_cachedGlyphData = new GlyphData(num, text.Length);
            GlyphShapeData glyphScriptShapeData = this.m_cachedGlyphData.GlyphScriptShapeData;
            int            num2 = Win32.ScriptShape(IntPtr.Zero, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);

            if (num2 == -2147483638)
            {
                flag = true;
                fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
            }
            if (num2 == -2147024882)
            {
                num = text.Length * 3;
                this.m_cachedGlyphData = new GlyphData(num, text.Length);
                glyphScriptShapeData   = this.m_cachedGlyphData.GlyphScriptShapeData;
                num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
            }
            if (!this.FallbackFont)
            {
                if (num2 == -2147220992)
                {
                    int num3 = 0;
                    num3 = ((!this.m_itemizedScriptId.HasValue) ? this.ScriptAnalysis.eScript : this.m_itemizedScriptId.Value);
                    this.m_cachedFont = fontCache.GetFallbackFont(this.m_textRunProps, this.GetCharset(), num3, verticalFont);
                    fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                    flag  = true;
                    flag2 = true;
                    num2  = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
                }
                else if (this.HasEastAsianChars)
                {
                    if (!flag)
                    {
                        fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                        flag = true;
                    }
                    Win32.SCRIPT_FONTPROPERTIES sCRIPT_FONTPROPERTIES = default(Win32.SCRIPT_FONTPROPERTIES);
                    sCRIPT_FONTPROPERTIES.cBytes = 16;
                    num2 = Win32.ScriptGetFontProperties(hdc, ref this.m_cachedFont.ScriptCache, ref sCRIPT_FONTPROPERTIES);
                    short wgDefault = sCRIPT_FONTPROPERTIES.wgDefault;
                    int   num4      = 0;
                    num4 = ((!this.m_itemizedScriptId.HasValue) ? this.ScriptAnalysis.eScript : this.m_itemizedScriptId.Value);
                    int num5 = 0;
                    while (num5 < glyphScriptShapeData.GlyphCount)
                    {
                        if (glyphScriptShapeData.Glyphs[num5] != wgDefault)
                        {
                            num5++;
                            continue;
                        }
                        this.m_cachedFont = fontCache.GetFallbackFont(this.m_textRunProps, this.GetCharset(), num4, verticalFont);
                        this.m_cachedFont.DefaultGlyph = wgDefault;
                        fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                        flag  = true;
                        flag2 = true;
                        num2  = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
                        break;
                    }
                }
            }
            if (num2 == -2147220992)
            {
                this.m_cachedFont = cachedFont;
                if (!flag || flag2)
                {
                    Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, this.m_cachedFont.Hfont);
                    win32ObjectSafeHandle.SetHandleAsInvalid();
                    flag = true;
                }
                flag2 = false;
                this.SetUndefinedScript();
                num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
            }
            if (Win32.Failed(num2))
            {
                Marshal.ThrowExceptionForHR(num2);
            }
            if (flag2)
            {
                this.FallbackFont = true;
            }
            this.m_cachedGlyphData.TrimToGlyphCount();
            this.m_cachedGlyphData.ScaleFactor = this.m_cachedFont.ScaleFactor;
            this.TextScriptPlace(hdc, flag, fontCache);
        }
예제 #12
0
        public int GetDescent(Win32DCSafeHandle hdc, FontCache fontCache)
        {
            CachedFont cachedFont = this.GetCachedFont(hdc, fontCache);

            return(cachedFont.GetDescent(hdc, fontCache));
        }