public static void InitializeFonts() { directWriteFactory = new Factory(); resourceFontLoader = new Direct2DResourceFontLoader(directWriteFactory); fontCollection = new FontCollection(directWriteFactory, resourceFontLoader, resourceFontLoader.Key); for (int i = 0; i < FontDefinitions.Length; i++) { var def = FontDefinitions[i]; def.Size = (int)(def.Size * mainWindowScaling); var format = new TextFormat(directWriteFactory, def.Name, fontCollection, def.Bold ? FontWeight.Bold : FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, def.Size); format.WordWrapping = WordWrapping.NoWrap; format.TextAlignment = def.Alignment == 1 ? TextAlignment.Center : (def.Alignment == 2 ? TextAlignment.Trailing : TextAlignment.Leading); if (def.Ellipsis) { var trimmingSign = new EllipsisTrimming(directWriteFactory, format); format.SetTrimming(new Trimming() { Delimiter = (int)')', Granularity = TrimmingGranularity.Character, DelimiterCount = 1 }, trimmingSign); } Fonts[i] = format; } }
internal D2dTextFormat(TextFormat textFormat) { if (textFormat == null) { throw new ArgumentNullException("textFormat"); } m_nativeTextFormat = textFormat; m_ellipsisTrimming = new EllipsisTrimming(D2dFactory.NativeDwFactory, m_nativeTextFormat); m_fontHeight = D2dFactory.FontSizeToPixel(m_nativeTextFormat.FontSize); }
public static void Initialize() { directWriteFactory = new SharpDX.DirectWrite.Factory(); resourceFontLoader = new ResourceFontLoader(directWriteFactory); fontCollection = new SharpDX.DirectWrite.FontCollection(directWriteFactory, resourceFontLoader, resourceFontLoader.Key); FontSmall = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 10.0f); FontMedium = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 12.0f); FontBig = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 20.0f); FontHuge = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 28.0f); FontSmallBold = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Bold, FontStyle.Normal, FontStretch.Normal, 10.0f); FontMediumBold = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Bold, FontStyle.Normal, FontStretch.Normal, 12.0f); FontBigBold = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Bold, FontStyle.Normal, FontStretch.Normal, 20.0f); FontSmallCenter = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 10.0f); FontSmallCenter.TextAlignment = TextAlignment.Center; FontSmallCenter.WordWrapping = WordWrapping.NoWrap; FontSmallRight = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 10.0f); FontSmallRight.TextAlignment = TextAlignment.Trailing; FontSmallRight.WordWrapping = WordWrapping.NoWrap; FontMediumRight = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 12.0f); FontMediumRight.TextAlignment = TextAlignment.Trailing; FontMediumRight.WordWrapping = WordWrapping.NoWrap; FontMediumCenter = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, 12.0f); FontMediumCenter.TextAlignment = TextAlignment.Center; FontMediumCenter.WordWrapping = WordWrapping.NoWrap; FontMediumBoldCenter = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Bold, FontStyle.Normal, FontStretch.Normal, 12.0f); FontMediumBoldCenter.TextAlignment = TextAlignment.Center; FontMediumBoldCenter.WordWrapping = WordWrapping.NoWrap; FontMediumBoldCenterEllipsis = new TextFormat(directWriteFactory, "Quicksand", fontCollection, FontWeight.Bold, FontStyle.Normal, FontStretch.Normal, 12.0f); FontMediumBoldCenterEllipsis.TextAlignment = TextAlignment.Center; FontMediumBoldCenterEllipsis.WordWrapping = WordWrapping.NoWrap; var trimmingSign = new EllipsisTrimming(directWriteFactory, FontMediumBoldCenterEllipsis); FontMediumBoldCenterEllipsis.SetTrimming(new Trimming() { Delimiter = (int)')', Granularity = TrimmingGranularity.Character, DelimiterCount = 1 }, trimmingSign); PrivateFontCollection = new PrivateFontCollection(); AddFontFromMemory(PrivateFontCollection, "FamiStudio.Resources.Quicksand-Regular.ttf"); AddFontFromMemory(PrivateFontCollection, "FamiStudio.Resources.Quicksand-Bold.ttf"); for (int j = 0; j < CustomColors.GetLength(1); j++) { for (int i = 0; i < CustomColors.GetLength(0); i++) { if (i == CustomColors.GetLength(0) - 1 && j == CustomColors.GetLength(1) - 1) { continue; } var color = CustomColors[i, j]; CustomColors[i, j] = System.Drawing.Color.FromArgb( Math.Min(255, color.R + 60), Math.Min(255, color.G + 60), Math.Min(255, color.B + 60)); } } OleLibrary = LoadLibrary("ole32.dll"); DragCursorHandle = LoadCursor(OleLibrary, 2); CopyCursorHandle = LoadCursor(OleLibrary, 3); DragCursor = new Cursor(DragCursorHandle); CopyCursor = new Cursor(CopyCursorHandle); }