public void ApplyStyle(HCCanvas ACanvas, Single AScale = 1) { ACanvas.Brush.Color = FBackColor; ACanvas.Font.BeginUpdate(); try { ACanvas.Font.Color = FColor; ACanvas.Font.Family = FFamily; if ((FFontStyles.Contains((byte)HCFontStyle.tsSuperscript)) || (FFontStyles.Contains((byte)HCFontStyle.tsSubscript))) { ACanvas.Font.Size = FSize / 2; } else { ACanvas.Font.Size = FSize; } ACanvas.Font.FontStyles = FFontStyles; } finally { ACanvas.Font.EndUpdate(); } }
private void ReCreateHandle() { ReleaseDC(); FLogFont.lfHeight = -(int)Math.Round(FSize * FPixelsPerInch / 72); // -Kernel.MulDiv(FSize, FPixelsPerInch, 72); FLogFont.lfWidth = 0; FLogFont.lfEscapement = 0; FLogFont.lfOrientation = 0; if (FFontStyles.Contains((byte)HCFontStyle.tsBold)) { FLogFont.lfWeight = GDI.FW_BOLD; } else { FLogFont.lfWeight = GDI.FW_NORMAL; } if (FFontStyles.Contains((byte)HCFontStyle.tsItalic)) { FLogFont.lfItalic = 1; } else { FLogFont.lfItalic = 0; } if (FFontStyles.Contains((byte)HCFontStyle.tsUnderline)) { FLogFont.lfUnderline = 1; } else { FLogFont.lfUnderline = 0; } if (FFontStyles.Contains((byte)HCFontStyle.tsStrikeOut)) { FLogFont.lfStrikeOut = 1; } else { FLogFont.lfStrikeOut = 0; } FLogFont.lfCharSet = GDI.DEFAULT_CHARSET; FLogFont.lfFaceName = FFamily; FLogFont.lfQuality = 0; FLogFont.lfOutPrecision = GDI.OUT_DEFAULT_PRECIS; FLogFont.lfClipPrecision = GDI.CLIP_DEFAULT_PRECIS; FLogFont.lfPitchAndFamily = GDI.DEFAULT_PITCH; if (FHandle == IntPtr.Zero) { FHandle = (IntPtr)GDI.CreateFontIndirect(ref FLogFont); } }
public void ApplyStyle(HCCanvas aCanvas, Single aScale = 1) { if (FBackColor == HC.HCTransparentColor) { aCanvas.Brush.Style = HCBrushStyle.bsClear; } else { aCanvas.Brush.Color = FBackColor; } aCanvas.Font.BeginUpdate(); try { aCanvas.Font.Color = FColor; aCanvas.Font.Family = FFamily; if ((FFontStyles.Contains((byte)HCFontStyle.tsSuperscript)) || (FFontStyles.Contains((byte)HCFontStyle.tsSubscript))) { aCanvas.Font.Size = FSize / 2; } else { aCanvas.Font.Size = FSize; } aCanvas.Font.FontStyles.Value = FFontStyles.Value; // 防止后面其他地方修改canva的font时影响到原始的样式数据 } finally { aCanvas.Font.EndUpdate(); } TEXTMETRICW vTextMetric = new TEXTMETRICW(); aCanvas.GetTextMetrics(ref vTextMetric); FTextMetric_tmAveCharWidth = vTextMetric.tmAveCharWidth; FTextMetric_tmExternalLeading = vTextMetric.tmExternalLeading; FTextMetric_tmHeight = vTextMetric.tmHeight; FONTSIGNATURE vFontSignature = new FONTSIGNATURE(); FFontHeight = aCanvas.TextHeight("H"); if ((GDI.GetTextCharsetInfo(aCanvas.Handle, ref vFontSignature, 0) != GDI.DEFAULT_CHARSET) && ((vFontSignature.fsCsb[0] & CJK_CODEPAGE_BITS) != 0)) { FCJKFont = true; } else { FCJKFont = false; } FOutMetSize = GDI.GetOutlineTextMetrics(aCanvas.Handle, 0, IntPtr.Zero); if (FOutMetSize != 0) { //FOutMetSize = (uint)Marshal.SizeOf(FOutlineTextmetric); IntPtr vOutlineTextmetricPtr = Marshal.AllocHGlobal((int)FOutMetSize); try { if (GDI.GetOutlineTextMetrics(aCanvas.Handle, FOutMetSize, vOutlineTextmetricPtr) != 0) { //FOutlineTextmetric = new OUTLINETEXTMETRICW(); //FOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(FOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); //string otmpFamilyName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFamilyName)); //string otmpFaceName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFaceName)); ; //string otmpStyleName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpStyleName)); ; //string otmpFullName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFullName)); ; // 以上为参考代码 //Marshal.PtrToStructure(FOutlineTextmetricPtr, FOutlineTextmetric); OUTLINETEXTMETRICW vOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(vOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); FOutlineTextmetric_otmfsSelection = vOutlineTextmetric.otmfsSelection; FOutlineTextmetric_otmAscent = vOutlineTextmetric.otmAscent; FOutlineTextmetric_otmDescent = vOutlineTextmetric.otmDescent; FOutlineTextmetric_otmEMSquare = vOutlineTextmetric.otmEMSquare; } } finally { Marshal.FreeHGlobal(vOutlineTextmetricPtr); } } TT_HHEA vFontHeader = new TT_HHEA(); if ((uint)GDI.GetFontData(aCanvas.Handle, MS_HHEA_TAG, 0, ref vFontHeader, Marshal.SizeOf(vFontHeader)) != GDI.GDI_ERROR) { FFontHeader_Ascender = vFontHeader.Ascender; FFontHeader_Descender = vFontHeader.Descender; } else { FFontHeader_Ascender = 0; FFontHeader_Descender = 0; } }
public void ApplyStyle(HCCanvas aCanvas, Single aScale = 1) { if (FBackColor == HC.HCTransparentColor) { aCanvas.Brush.Style = HCBrushStyle.bsClear; } else { aCanvas.Brush.Color = FBackColor; } aCanvas.Font.BeginUpdate(); try { aCanvas.Font.Color = FColor; aCanvas.Font.Family = FFamily; if ((FFontStyles.Contains((byte)HCFontStyle.tsSuperscript)) || (FFontStyles.Contains((byte)HCFontStyle.tsSubscript))) { aCanvas.Font.Size = FSize / 2; } else { aCanvas.Font.Size = FSize; } aCanvas.Font.FontStyles = FFontStyles; } finally { aCanvas.Font.EndUpdate(); } aCanvas.GetTextMetrics(ref FTextMetric); FONTSIGNATURE vFontSignature = new FONTSIGNATURE(); FFontHeight = aCanvas.TextHeight("H"); if ((GDI.GetTextCharsetInfo(aCanvas.Handle, ref vFontSignature, 0) != GDI.DEFAULT_CHARSET) && ((vFontSignature.fsCsb[0] & CJK_CODEPAGE_BITS) != 0)) { FCJKFont = true; } else { FCJKFont = false; } if (FOutMetSize > 0) { Marshal.FreeHGlobal(FOutlineTextmetricPtr); } FOutMetSize = GDI.GetOutlineTextMetrics(aCanvas.Handle, 0, IntPtr.Zero); if (FOutMetSize != 0) { //FOutMetSize = (uint)Marshal.SizeOf(FOutlineTextmetric); FOutlineTextmetricPtr = Marshal.AllocHGlobal((int)FOutMetSize); if (GDI.GetOutlineTextMetrics(aCanvas.Handle, FOutMetSize, FOutlineTextmetricPtr) != 0) { //FOutlineTextmetric = new OUTLINETEXTMETRICW(); //FOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(FOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); //string otmpFamilyName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFamilyName)); //string otmpFaceName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFaceName)); ; //string otmpStyleName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpStyleName)); ; //string otmpFullName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFullName)); ; // 以上为参考代码 //Marshal.PtrToStructure(FOutlineTextmetricPtr, FOutlineTextmetric); FOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(FOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); } } if ((uint)GDI.GetFontData(aCanvas.Handle, MS_HHEA_TAG, 0, ref FFontHeader, Marshal.SizeOf(FFontHeader)) == GDI.GDI_ERROR) { return; } }