public FontInfo(int height, int startChar, int endChar, ushort[] fontDescriptors, byte[] fontBitmaps, string name, ushort id) { _fontCharInfo = new FontCharInfo(); Height = height; StartChar = startChar; EndChar = endChar; CharInfo = fontDescriptors; Data = fontBitmaps; Name = name; ID = id; }
public int GetStringWidth(string text) { var width = 0; var startChar = StartChar; foreach (var characterToOutput in text) { FontCharInfo fontCharInfo = GetFontCharInfo(characterToOutput); width += fontCharInfo.WidthBits + 1; } return(width); }
public int sceFontGetCharInfo(Font Font, ushort CharCode, ref FontCharInfo FontCharInfoPointer) { try { FontCharInfoPointer = Font.GetCharInfo(CharCode); Console.WriteLine("sceFontGetCharInfo({0}) : {1}", CharCode, FontCharInfoPointer); return(0); } catch (Exception Exception) { Console.Error.WriteLine(Exception); return(-1); } }
public int sceFontGetCharInfo(FontHandle FontHandle, ushort CharCode, ref FontCharInfo FontCharInfoPointer) { try { var Font = Fonts.Get(FontHandle); FontCharInfoPointer = Font.GetCharInfo(CharCode); Console.WriteLine("sceFontGetCharInfo({0}) : {1}", CharCode, FontCharInfoPointer); return 0; } catch (Exception Exception) { Console.Error.WriteLine(Exception); return -1; } }
/// <summary> /// 根据单个字符生成字库图片 /// </summary> /// <param name="fontChar"></param> /// <returns></returns> private Bitmap CreateCharBitMap(string fontChar) { Bitmap bmp = new Bitmap(this.fontWidth, this.fontHeight); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.FromArgb(0, 0, 0, 0)); g.SmoothingMode = SmoothingMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; Pen blackPen = new Pen(Color.Black, 0.01F); if (this.isUseOld && this.comOldFont.Contains(fontChar)) { // 取得原有的字库 int fontW = 0x1C; int fontH = 0x1C; int index = 0; int charFontIndex = 0; for (int i = 0; i < this.comOldFont.Length; i++) { if (fontChar == this.comOldFont[i]) { index = i; break; } } // 根据旧字符宽度信息,设置新字符宽度信息 this.newFontCharInfoLst.Add(new FontCharInfo()); // 取得旧字库图片 this.fontBmp = new Bitmap(@"..\BioTools\Bio0Edit\bio0ComFont.bmp"); for (int y = 0; y < this.fontBmp.Height; y += fontH) { for (int x = 0; x < this.fontBmp.Width; x += fontW) { if (charFontIndex == index) { for (int yPixel = 0; yPixel < fontH; yPixel++) { for (int xPixel = 0; xPixel < fontW; xPixel++) { bmp.SetPixel(xPixel, yPixel, this.fontBmp.GetPixel(x + xPixel, y + yPixel)); } } return(bmp); } charFontIndex++; } } } else { FontCharInfo charInfo = new FontCharInfo(); if (string.IsNullOrEmpty(fontChar)) { // 更新进度条 this.ProcessBarStep(); return(bmp); } else if (" " == fontChar) { charInfo.LeftPadding = this.fontWidth; charInfo.Width = 0; this.newFontCharInfoLst.Add(charInfo); // 更新进度条 this.ProcessBarStep(); return(bmp); } // 单个子对齐风格 StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Near; CharacterRange[] characterRanges = { new CharacterRange(0, 1) }; sf.SetMeasurableCharacterRanges(characterRanges); // 在指定的区域内写入特定汉字 RectangleF rectangle = new RectangleF(0, 0, this.fontWidth, this.fontHeight); GraphicsPath graphPath = new GraphicsPath(); graphPath.AddString(fontChar, new FontFamily(txtFontTest.Font.Name), (int)FontStyle.Bold, this.fontHeight, rectangle, sf); g.FillPath(Brushes.White, graphPath); g.DrawPath(blackPen, graphPath); //rectangle.Offset(-1, 0); // 绘制左背景文字 //g.DrawString(fontChar, this.selectedFont, Brushes.Black, rectangle, sf); //rectangle.Offset(2, 0); // 绘制右背景文字 //g.DrawString(fontChar, this.selectedFont, Brushes.Black, rectangle, sf); //rectangle.Offset(-1, -1); // 绘制下背景文字 //g.DrawString(fontChar, this.selectedFont, Brushes.Black, rectangle, sf); //rectangle.Offset(0, 2); // 绘制上背景文字 //g.DrawString(fontChar, this.selectedFont, Brushes.Black, rectangle, sf); //rectangle.Offset(0, -1); // 定位点归位 //// 绘制前景文字 //g.DrawString(fontChar, this.selectedFont, Brushes.White, rectangle, sf); // 设置字符宽度信息 Region[] charRegions = g.MeasureCharacterRanges(fontChar, this.selectedFont, rectangle, sf); int charWidth = (int)charRegions[0].GetBounds(g).Width; int charLeftWidth = this.fontWidth + 1 - charWidth; if (charLeftWidth <= 0) { charLeftWidth = 0; } else if (charLeftWidth % 2 != 0) { charLeftWidth = charLeftWidth / 2 + 1; } else { charLeftWidth = charLeftWidth / 2; } charInfo.LeftPadding = charLeftWidth; charInfo.Width = charLeftWidth + charWidth; this.newFontCharInfoLst.Add(charInfo); } // 更新进度条 this.ProcessBarStep(); return(bmp); }
public int sceFontGetCharInfo(FontHandle FontHandle, ushort CharCode, FontCharInfo* FontCharInfoPointer) { var Font = Fonts.Get(FontHandle); *FontCharInfoPointer = Font.GetCharInfo(CharCode); return 0; }
public int sceFontGetCharInfo(FontHandle fontHandle, uint charCode, FontCharInfo* fontCharInfo) { throw(new NotImplementedException()); }