예제 #1
0
        private void CreateBitmap(int width, int height)
        {
//			if (_bitmap == null || (_bitmap.Width < width || _bitmap.Height < height))
//			{

            _bitmap = CCLabelUtilities.CreateBitmap(width, height);
            //}

            //if (_brush == null)
            //{
            _brush = CCColor4B.White;
            //}
        }
예제 #2
0
        private unsafe byte *GetBitmapData(string s, out int stride)
        {
            var size = GetMeasureString(s);

            var w = (int)(Math.Ceiling(size.Width += 2));
            var h = (int)(Math.Ceiling(size.Height += 2));

            CreateBitmap(w, h);

            CCLabelUtilities.NativeDrawString(_bitmap, s, _font, _brush, new RectangleF(0, 0, w, h));
            _bitmapData = _bitmap.Data;

            stride = _bitmap.BytesPerRow;

            return((byte *)_bitmapData);
        }
예제 #3
0
        private void CreateFont(string fontName, float fontSize, CCRawList <char> charset)
        {
            _font = CCLabelUtilities.CreateFont(fontName, fontSize);

            var value = new CCLabelUtilities.ABCFloat[1];

            _abcValues.Clear();;

            for (int i = 0; i < charset.Count; i++)
            {
                var ch = charset[i];
                CCLabelUtilities.GetCharABCWidthsFloat(ch, _font, out value);
                _abcValues.Add(ch, new KerningInfo()
                {
                    A = value[0].abcfA, B = value[0].abcfB, C = value[0].abcfC
                });
            }
        }
예제 #4
0
        private Font CreateFont(string fontName, float fontSize)
        {
            Font currentFont;

            if (_defaultFont == null)
            {
                _defaultFont = new Font(FontFamily.GenericSansSerif, 12);
            }

            FontFamily fontFamily;

            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        // Read the font file bytes
                        var fontBytes = CCContentManager.SharedContentManager.GetAssetStreamAsBytes(fontName);

                        // Pin the font data for the length of the read file
                        var fontData = Marshal.AllocCoTaskMem(fontBytes.Length);

                        // Copy the font data to our memory
                        Marshal.Copy(fontBytes, 0, fontData, fontBytes.Length);

                        // Add the memory data to our private font collection as a Font in Memory
                        loadedFontsCollection.AddMemoryFont(fontData, fontBytes.Length);

                        // Release the pinned data
                        Marshal.FreeCoTaskMem(fontData);

                        // Try to get the family name of the
                        var ttfFontFamily = CCLabelUtilities.GetFontFamily(fontBytes, 0);

                        fontFamily = new FontFamily(ttfFontFamily, loadedFontsCollection);

                        currentFont = new Font(fontFamily, fontSize);
                    }
                    catch
                    {
                        currentFont = _defaultFont;
                    }
                }
                else
                {
                    currentFont = new Font(fontName, fontSize);
                }

                _fontFamilyCache.Add(fontName, currentFont.FontFamily);
            }
            else
            {
                currentFont = new Font(fontFamily, fontSize);
            }

            // Create a small bitmap to be used for our graphics context
            CreateBitmap(1, 1);

            return(currentFont);
        }
예제 #5
0
 private CCSize GetMeasureString(string text)
 {
     return(CCLabelUtilities.MeasureString(text, _font));
 }