private void TurnOnCategory(FontCategory category, double zoomLevel) { Guid categoryId = category.Id; int hr = fontsAndColors.OpenCategory( ref categoryId, (uint)(__FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS) ); if (ErrorHandler.Succeeded(hr)) { LOGFONTW[] logfont = new LOGFONTW[1]; FontInfo[] fontInfo = new FontInfo[1]; hr = fontsAndColors.GetFont(logfont, fontInfo); if (ErrorHandler.Succeeded(hr)) { category.FontInfo = fontInfo[0]; double size = fontInfo[0].wPointSize; size = (size * zoomLevel) / 100; fontInfo[0].bFaceNameValid = 0; fontInfo[0].bCharSetValid = 0; fontInfo[0].bPointSizeValid = 1; fontInfo[0].wPointSize = Convert.ToUInt16(size); fontsAndColors.SetFont(fontInfo); } fontsAndColors.CloseCategory(); } }
public static void CreateLogFont(IntPtr window, Font font, out LOGFONTW lf) { const int LOGPIXELSY = 90; lf = new LOGFONTW(); IntPtr dc; int dpi_y; dc = GetDC(window); { dpi_y = GetDeviceCaps(dc, LOGPIXELSY); } ReleaseDC(window, dc); lf.escapement = 0; lf.orientation = 0; lf.height = -(int)(font.Size * dpi_y / 72); lf.weight = (font.Style & FontStyle.Bold) != 0 ? 700 : 400; // FW_BOLD or FW_NORMAL lf.italic = (byte)((font.Style & FontStyle.Italic) != 0 ? 1 : 0); lf.underline = 0; //(byte)( (font.Style & FontStyle.Underline) != 0 ? 1 : 0 ); lf.strikeOut = 0; //(byte)( (font.Style & FontStyle.Strikeout) != 0 ? 1 : 0 ); lf.charSet = 1; // DEFAULT_CHARSET lf.outPrecision = 0; // OUT_DEFAULT_PRECIS lf.clipPrecision = 0; // CLIP_DEFAULT_PRECIS lf.quality = 0; // DEFAULT_QUALITY lf.pitchAndFamily = 0; // DEFAULT_PITCH // set font name lf.faceName = font.Name; }
internal static void AdjustFontSize(IServiceProvider serviceProvider, Guid category, short change) { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)serviceProvider.GetService(typeof(SVsFontAndColorStorage)); IVsFontAndColorUtilities utilities = storage as IVsFontAndColorUtilities; LOGFONTW[] pLOGFONT = new LOGFONTW[1]; FontInfo[] pInfo = new FontInfo[1]; ErrorHandler.ThrowOnFailure(storage.OpenCategory(category, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES))); try { if (!ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo))) { return; } pInfo[0].wPointSize = checked ((ushort)(pInfo[0].wPointSize + change)); ErrorHandler.ThrowOnFailure(storage.SetFont(pInfo)); ErrorHandler.ThrowOnFailure(utilities.FreeFontInfo(pInfo)); } finally { storage.CloseCategory(); } }
/// <summary> /// Sample Font Global Hook (Hook any call of the target process) /// <para> Warning: This is just a sample, don't works with any application, tested with notepad. /// This only hooks the CreateFontIndirectW, we have it CreateFontA, CreateFontW and CreateFontIndirectA to handle with others programs</para> /// </summary> public static void GlobalHookFont() { //Attachs the Debugger Debugger.Launch(); //Create the delegate and assign the hook function to him dCreateFontIndirect = new CreateFontIndirectWDelegate(CreateFontIndirectWHook); //Create to the given dll export with the given delegate hCreateFontIndirect = new UnmanagedHook <CreateFontIndirectWDelegate>("gdi32.dll", "CreateFontIndirectW", dCreateFontIndirect); //Install the Hook hCreateFontIndirect.Install(); //Allow the process Execution and test the hook new Thread(() => { Thread.Sleep(1000); //As you can see, will create a font with the facename Times New Roman LOGFONTW Font = new LOGFONTW(); Font.lfFaceName = "Times New Roman"; CreateFontIndirectW(ref Font); //Or is what you think... MessageBox.Show($"Font Selected: {Font.lfFaceName}", "Injected Assembly", MessageBoxButtons.OK, MessageBoxIcon.Information); }).Start(); }
//A method that matchs with the hook delegate public static IntPtr CreateFontIndirectWHook(ref LOGFONTW lplf) { lplf.lfFaceName = "Comic Sans MS"; //Call the original CreateFontIndirect return(CreateFontIndirectW(ref lplf)); }
public static LOGFONTW FromFont(Font font, Graphics graphics) { object logFont = new LOGFONTW(); font.ToLogFont(logFont, graphics); return((LOGFONTW)logFont); }
public static void GetFontSettings(string categoryGuid, out string fontName, out int fontSize) { ThreadHelper.ThrowIfNotOnUIThread(); var storage = (IVsFontAndColorStorage)ServiceProvider.GlobalProvider.GetService(typeof(SVsFontAndColorStorage)); if (storage == null) { goto EXIT; } var pLOGFONT = new LOGFONTW[1]; var pInfo = new FontInfo[1]; ErrorHandler.ThrowOnFailure(storage.OpenCategory(new Guid(categoryGuid), (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES))); try { if (ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo))) { fontName = pInfo[0].bstrFaceName; fontSize = pInfo[0].wPointSize; return; } } finally { storage.CloseCategory(); } EXIT: fontName = null; fontSize = 0; }
public unsafe void CreateFontIndirect() { LOGFONTW logFont = default; Gdi32.HFONT handle = Gdi32.CreateFontIndirectW(ref logFont); Assert.False(handle.IsNull); Assert.True(Gdi32.DeleteObject(handle).IsTrue()); }
public unsafe void CreateFontIndirect() { LOGFONTW logFont = default; IntPtr handle = Gdi32.CreateFontIndirectW(ref logFont); Assert.NotEqual(IntPtr.Zero, handle); Assert.True(Gdi32.DeleteObject(handle).IsTrue()); }
public void TextBoxBaseUiaTextProvider_GetLogfont_ReturnSegoe_ByDefault() { using TextBoxBase textBoxBase = new SubTextBoxBase(); Assert.NotEqual(IntPtr.Zero, textBoxBase.Handle); TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase); LOGFONTW logFont = provider.Logfont; string actual = logFont.FaceName.ToString(); Assert.Equal("Segoe UI", actual); Assert.True(textBoxBase.IsHandleCreated); }
public void TextBoxBaseUiaTextProvider_GetLogfont_ReturnsEmpty_WithoutHandle() { using TextBoxBase textBoxBase = new SubTextBoxBase(); TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase); LOGFONTW expected = new LOGFONTW(); LOGFONTW actual = provider.Logfont; Assert.True(string.IsNullOrEmpty(actual.FaceName.ToString())); Assert.Equal(expected, actual); Assert.False(textBoxBase.IsHandleCreated); }
private async Task LoadSystemTextSettingsAsync(CancellationToken cancellationToken) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); try { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { #pragma warning disable SA1129 // Do not use default value type constructor LOGFONTW[] fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] info = new FontInfo[] { new FontInfo() }; #pragma warning restore SA1129 // Do not use default value type constructor if (storage.GetFont(fnt, info) == Microsoft.VisualStudio.VSConstants.S_OK) { var fontSize = info[0].wPointSize; if (fontSize > 0) { ResourceAdornmentManager.TextSize = fontSize; } } } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; // Get the color value configured for regular string display if (storage.GetItem("String", info) == Microsoft.VisualStudio.VSConstants.S_OK) { var win32Color = (int)info[0].crForeground; int r = win32Color & 0x000000FF; int g = (win32Color & 0x0000FF00) >> 8; int b = (win32Color & 0x00FF0000) >> 16; var textColor = Color.FromRgb((byte)r, (byte)g, (byte)b); ResourceAdornmentManager.TextForegroundColor = textColor; } } } catch (Exception exc) { ExceptionHelper.Log(exc, "Error in LoadSystemTextSettingsAsync"); } }
public void *CreateFontIndirect(ref LOGFONTW Info) { var Remap = EntryPoint.SRL.ResolveRemap(Info.lfFaceName, Info.lfWidth, Info.lfHeight, Info.lfCharSet); if (Remap != null) { Info.lfHeight = Remap.Value.Height; Info.lfWidth = Remap.Value.Width; Info.lfFaceName = Remap.Value.To; Info.lfCharSet = (byte)Remap.Value.Charset; } return(Bypass(ref Info)); }
internal FontInfo GetFontSettings(Guid category) { var storage = (IVsFontAndColorStorage)GetService(typeof(SVsFontAndColorStorage)); var pLOGFONT = new LOGFONTW[1]; var pInfo = new FontInfo[1]; ErrorHandler.ThrowOnFailure(storage.OpenCategory(category, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES))); try { return(ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo)) ? pInfo[0] : default(FontInfo)); } finally { storage.CloseCategory(); } }
public void TextBoxBaseUiaTextProvider_GetLogfont_ReturnsCorrectValue() { using (new NoAssertContext()) { using TextBoxBase textBoxBase = new SubTextBoxBase(); textBoxBase.CreateControl(); TextBoxBaseUiaTextProvider provider = new TextBoxBaseUiaTextProvider(textBoxBase); LOGFONTW expected = LOGFONTW.FromFont(textBoxBase.Font); LOGFONTW actual = provider.Logfont; Assert.False(string.IsNullOrEmpty(actual.FaceName.ToString())); Assert.Equal(expected, actual); Assert.True(textBoxBase.IsHandleCreated); } }
public (string name, float size) GetFontInfo() { ThreadHelper.ThrowIfNotOnUIThread(); try { var fontw = new LOGFONTW[1]; var fontInfo = new FontInfo[1]; ErrorHandler.ThrowOnFailure(_storage.GetFont(fontw, fontInfo)); return(name : fontInfo[0].bstrFaceName, size : fontInfo[0].wPointSize); } catch { return(Control.DefaultFont.Name, Control.DefaultFont.Size); } }
static IntPtr hCreateFontIndirectW(ref LOGFONTW FontInfo) { if (RedirFontSize(FontInfo.lfFaceName) != null) { string Change = RedirFontSize(FontInfo.lfFaceName); if (Change.StartsWith("+")) { FontInfo.lfWidth += int.Parse(Change); } else { int Val = int.Parse(Change); if (Val <= 0) { FontInfo.lfWidth += Val; } else { FontInfo.lfWidth = Val; } } } FontInfo.lfFaceName = RedirFaceName(FontInfo.lfFaceName); if (FontCharset != 0) { FontInfo.lfCharSet = FontCharset; } if (LogInput) { Log("CreateIndirectW Hooked, {0} 0x{1:X2}", true, FontInfo.lfFaceName, FontInfo.lfCharSet); } if (hCreatFontIndirectW.ImportHook) { return(CreateFontIndirectW(ref FontInfo)); } hCreatFontIndirectW.Uninstall(); var Result = CreateFontIndirectW(ref FontInfo); hCreatFontIndirectW.Install(); return(Result); }
public static unsafe void CreateLogFont(IntPtr window, FontInfo font, out LOGFONTW lf) { //DO_NOT//Debug.Assert( window != IntPtr.Zero ); Debug.Assert(font != null); Debug.Assert(font.Name != null); const int LOGPIXELSY = 90; lf = new LOGFONTW(); IntPtr dc; int dpi_y; dc = GetDC(window); { dpi_y = GetDeviceCaps(dc, LOGPIXELSY); } ReleaseDC(window, dc); lf.escapement = 0; lf.orientation = 0; lf.height = -(int)(font.Size * dpi_y / 72); lf.weight = (font.Style & FontStyle.Bold) != 0 ? 700 : 400; // FW_BOLD or FW_NORMAL lf.italic = (byte)((font.Style & FontStyle.Italic) != 0 ? 1 : 0); lf.underline = 0; //(byte)( (font.Style & FontStyle.Underline) != 0 ? 1 : 0 ); lf.strikeOut = 0; //(byte)( (font.Style & FontStyle.Strikeout) != 0 ? 1 : 0 ); lf.charSet = 1; // DEFAULT_CHARSET lf.outPrecision = 0; // OUT_DEFAULT_PRECIS lf.clipPrecision = 0; // CLIP_DEFAULT_PRECIS lf.quality = 0; // DEFAULT_QUALITY lf.pitchAndFamily = 0; // DEFAULT_PITCH // set font name fixed(char *p = lf.faceName) { for (int i = 0; i < 32; i++) { if (font.Name.Length <= i || font.Name[i] == '\0') { return; } p[i] = font.Name[i]; } p[31] = '\0'; } }
public unsafe void LogFont_FaceName() { LOGFONTW logFont = default; logFont.FaceName = "TwoFace"; Assert.Equal("TwoFace", logFont.FaceName.ToString()); // Set a smaller name to make sure it gets terminated properly. logFont.FaceName = "Face"; Assert.Equal("Face", logFont.FaceName.ToString()); // LOGFONT has space for 32 characters, we want to see it gets // cut to 31 to make room for the null. string bigString = new string('*', 32); logFont.FaceName = bigString; Assert.True(logFont.FaceName.SequenceEqual(bigString.AsSpan().Slice(1))); }
private static void GetSize() { try { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)Package.GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { LOGFONTW[] Fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] Info = new FontInfo[] { new FontInfo() }; storage.GetFont(Fnt, Info); _fontSize = (int)Info[0].wPointSize; } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; storage.GetItem("Plain Text", info); _backgroundColor = ConvertFromWin32Color((int)info[0].crBackground); } } catch { } }
private static void GetSize() { try { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)EditorExtensionsPackage.GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { LOGFONTW[] Fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] Info = new FontInfo[] { new FontInfo() }; storage.GetFont(Fnt, Info); _fontSize = (int)Info[0].wPointSize; } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; storage.GetItem("Plain Text", info); _backgroundColor = ConvertFromWin32Color((int)info[0].crBackground); } } catch { } }
public static async Task AdjustFontSizeAsync(string categoryGuid, short change) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsFontAndColorStorage storage = await VS.Shell.GetFontAndColorStorageAsync(); Assumes.Present(storage); // ReSharper disable once SuspiciousTypeConversion.Global var utilities = storage as IVsFontAndColorUtilities; if (utilities == null) { return; } var pLOGFONT = new LOGFONTW[1]; var pInfo = new FontInfo[1]; var category = new Guid(categoryGuid); ErrorHandler.ThrowOnFailure(storage.OpenCategory(category, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES))); try { if (!ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo))) { return; } pInfo[0].wPointSize = checked ((ushort)(pInfo[0].wPointSize + change)); ErrorHandler.ThrowOnFailure(storage.SetFont(pInfo)); ErrorHandler.ThrowOnFailure(utilities.FreeFontInfo(pInfo)); } finally { storage.CloseCategory(); } }
static extern IntPtr CreateFontIndirectW([In] ref LOGFONTW FontInfo);
private void ClearCache() { if (myColors != null) { myColors = null; myLogFont = new LOGFONTW(); myFontInfo = new FontInfo(); } }
/// <summary> /// Implements IVsFontAndColorEvents.OnFontChanged /// </summary> protected int OnFontChanged(ref Guid rguidCategory, FontInfo[] pInfo, LOGFONTW[] pLOGFONT, uint HFONT) { OnChange(ref rguidCategory); return VSConstants.S_OK; }
static extern IntPtr CreateFontIndirectW([In, Out] ref LOGFONTW lplf);
public int OnFontChanged(ref Guid rguidCategory, FontInfo[] pInfo, LOGFONTW[] pLOGFONT, uint HFONT) { return VSConstants.S_OK; }
/// <summary> /// Retrieve font information for the current category /// </summary> /// <param name="logFont">LOGFONTW structure (out)</param> /// <param name="fontInfo">FontInfo structure (out)</param> public void GetFont(out LOGFONTW logFont, out FontInfo fontInfo) { EnsureStorage(); LOGFONTW[] logFontParam = new LOGFONTW[1]; FontInfo[] fontInfoParam = new FontInfo[1]; ErrorHandler.ThrowOnFailure(myStorage.GetFont(logFontParam, fontInfoParam)); logFont = logFontParam[0]; fontInfo = fontInfoParam[0]; }
public void ReloadFontAndColors() { ThreadHelper.ThrowIfNotOnUIThread(); m_fontInfoInitialized = true; #region fill out temorary resources var colorStorage = FontAndColorStorage; var categoryGuid = CategoryGuid; var fflags = (UInt32)__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | (UInt32)__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | (UInt32)__FCSTORAGEFLAGS.FCSF_READONLY; if (ErrorHandler.Succeeded(colorStorage.OpenCategory(ref categoryGuid, fflags))) { try { var pLOGFONT = new LOGFONTW[1]; var pFontInfo = new FontInfo[1]; if (ErrorHandler.Succeeded(colorStorage.GetFont(pLOGFONT, pFontInfo)) && (pFontInfo[0].bFaceNameValid == 1)) { var fontInfoRef = pFontInfo[0]; var fontFamily = new FontFamily(fontInfoRef.bstrFaceName); var fontSize = ConvertFromPoint(fontInfoRef.wPointSize); m_resourceDictionary[new FontResourceKey(CategoryGuid, FontResourceKeyType.FontFamily)] = fontFamily; m_resourceDictionary[new FontResourceKey(CategoryGuid, FontResourceKeyType.FontSize)] = fontSize; } else { m_resourceDictionary.Remove(new FontResourceKey(CategoryGuid, FontResourceKeyType.FontFamily)); m_resourceDictionary.Remove(new FontResourceKey(CategoryGuid, FontResourceKeyType.FontSize)); } foreach (var colorEntry in ColorEntries) { Color?backgroundColor = null; Color?foregroundColor = null; var pColorInfo = new ColorableItemInfo[1]; if (ErrorHandler.Succeeded(colorStorage.GetItem(colorEntry.Name, pColorInfo))) { if (pColorInfo[0].bBackgroundValid == 1) { backgroundColor = Services.CreateWpfColor(pColorInfo[0].crBackground); } if (pColorInfo[0].bForegroundValid == 1) { foregroundColor = Services.CreateWpfColor(pColorInfo[0].crForeground); } } colorEntry.UpdateResources(m_resourceDictionary, backgroundColor, foregroundColor); } } finally { colorStorage.CloseCategory(); } } #endregion }
static extern Int32 ImmSetCompositionFontW(IntPtr imContext, ref LOGFONTW logFont);
private async void HandleOpenSolution(object sender = null, EventArgs e = null) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(); //Use nested methods to avoid prompt (and need) for multiple MainThead checks/switches IEnumerable <ProjectItem> RecurseProjectItems(ProjectItems projItems) { if (projItems != null) { foreach (ProjectItem item in projItems) { foreach (var subItem in RecurseProjectItem(item)) { yield return(subItem); } } } } IEnumerable <ProjectItem> RecurseProjectItem(ProjectItem item) { yield return(item); foreach (var subItem in RecurseProjectItems(item.ProjectItems)) { yield return(subItem); } } IEnumerable <ProjectItem> GetProjectFiles(Project proj) { foreach (ProjectItem item in RecurseProjectItems(proj.ProjectItems)) { yield return(item); } } // TODO: handle res files being removed or added to a project - currently will be ignored. Issue #2 // Get all resource files from the solution // Do this now, rather than in adornment manager for performance and to avoid thread issues if (await this.GetServiceAsync(typeof(DTE)) is DTE dte) { foreach (var project in dte.Solution.Projects) { foreach (var solFile in GetProjectFiles((Project)project)) { var filePath = solFile.FileNames[0]; var fileExt = System.IO.Path.GetExtension(filePath); // Only interested in resx files if (fileExt.Equals(".resx")) { // Only want neutral language ones, not locale specific versions if (!System.IO.Path.GetFileNameWithoutExtension(filePath).Contains(".")) { ResourceAdornmentManager.ResourceFiles.Add(filePath); } } } } IVsFontAndColorStorage storage = (IVsFontAndColorStorage)VSPackage.GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); // Seem like reasonabel defaults as should be visible on light & dark theme int _fontSize = 10; Color _textColor = Colors.Gray; if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { LOGFONTW[] Fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] Info = new FontInfo[] { new FontInfo() }; storage.GetFont(Fnt, Info); _fontSize = Info[0].wPointSize; } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == Microsoft.VisualStudio.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; // Get the color value configured for regular string display storage.GetItem("String", info); var win32Color = (int)info[0].crForeground; int r = win32Color & 0x000000FF; int g = (win32Color & 0x0000FF00) >> 8; int b = (win32Color & 0x00FF0000) >> 16; _textColor = Color.FromRgb((byte)r, (byte)g, (byte)b); } ResourceAdornmentManager.TextSize = _fontSize; ResourceAdornmentManager.TextForegroundColor = _textColor; var plural = ResourceAdornmentManager.ResourceFiles.Count > 1 ? "s" : string.Empty; (await this.GetServiceAsync(typeof(DTE)) as DTE).StatusBar.Text = $"String Resource Visualizer initialized with {ResourceAdornmentManager.ResourceFiles.Count} resource file{plural}."; } }
private void TurnOnCategory(FontCategory category, double zoomLevel) { Guid categoryId = category.Id; int hr = fontsAndColors.OpenCategory( ref categoryId, (uint)(__FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS) ); if ( ErrorHandler.Succeeded(hr) ) { LOGFONTW[] logfont = new LOGFONTW[1]; FontInfo[] fontInfo = new FontInfo[1]; hr = fontsAndColors.GetFont(logfont, fontInfo); if ( ErrorHandler.Succeeded(hr) ) { category.FontInfo = fontInfo[0]; double size = fontInfo[0].wPointSize; size = (size * zoomLevel) / 100; fontInfo[0].bFaceNameValid = 0; fontInfo[0].bCharSetValid = 0; fontInfo[0].bPointSizeValid = 1; fontInfo[0].wPointSize = Convert.ToUInt16(size); fontsAndColors.SetFont(fontInfo); } fontsAndColors.CloseCategory(); } }
int IVsFontAndColorEvents.OnFontChanged(ref Guid rguidCategory, FontInfo[] pInfo, LOGFONTW[] pLOGFONT, uint HFONT) { return OnFontChanged(ref rguidCategory, pInfo, pLOGFONT, HFONT); }