Ejemplo n.º 1
0
        static WinGdiFont SetFont(RequestFont font)
        {
            WinGdiFont winFont = WinGdiFontSystem.GetWinGdiFont(font);

            MyWin32.SelectObject(win32MemDc.DC, winFont.CachedHFont());
            return(winFont);
        }
Ejemplo n.º 2
0
        //==============================================

        public static void CalculateGlyphAdvancePos(char[] str, int startAt, int len, RequestFont font, int[] glyphXAdvances)
        {
            unsafe
            {
                if (len == 0)
                {
                    return;
                }

                WinGdiFont winfont = SetFont(font);
                //ushort* glyhIndics = stackalloc ushort[len];
                //fixed (char* s = &str[startAt])
                //{
                //    NativeTextWin32.GetGlyphIndices(
                //        win32MemDc.DC,
                //        s,
                //        len,
                //        glyhIndics,
                //        0);
                //}
                byte[] encoding = s_en.GetBytes(str, startAt, len);
                NativeTextWin32.FontABC[] abcWidths = winfont.GetInteralABCArray();
                for (int i = 0; i < len; ++i)
                {
                    //ushort glyphIndex = *(glyhIndics + i);
                    int enc_index = encoding[i];
                    if (enc_index == 0)
                    {
                        break;//?
                    }
                    glyphXAdvances[i] = abcWidths[enc_index].Sum;
                }
            }
        }
Ejemplo n.º 3
0
        public static WinGdiFont GetWinGdiFont(RequestFont f)
        {
            if (f == null)
            {
                throw new NotSupportedException();
            }
            if (f == latestFont)
            {
                return(latestWinFont);
            }
            WinGdiFont actualFontInside = WinGdiFont.GetCacheFontAsWinGdiFont(f);

            if (actualFontInside != null)
            {
                return(actualFontInside);
            }
            //-----
            //need to create a new one
            //get register font or create the new one
            FontKey    key = f.FontKey;
            WinGdiFont found;

            if (!registerFonts.TryGetValue(key, out found))
            {
                //create the new one and register
                //create fontface
                FontFaceKey    fontfaceKey = new FontFaceKey(key);
                WinGdiFontFace fontface;
                if (!winGdiFonFaces.TryGetValue(fontfaceKey, out fontface))
                {
                    //create new
                    fontface = new WinGdiFontFace(f.Name);
                    winGdiFonFaces.Add(fontfaceKey, fontface);
                }

                var winGdiFont = new WinGdiFont(fontface, f.SizeInPoints, FontStyle.Regular);
                found = winGdiFont;
                registerFonts.Add(key, found);//cache here
            }
            latestFont = f;
            RequestFontImpl reqFont = (RequestFontImpl)f;

            if (reqFont._platformFont == null)
            {
                reqFont._platformFont = found;
            }

            //found.AssignToRequestFont(f);
            return(latestWinFont = found);
        }