How to get or calculate true background color of code comments in a VS2022 extension

Laurent Abélard 1 Reputation point
2022-08-02T12:47:51.347+00:00

I am creating an extension to add comment formatting in HTML but I have some difficulties with background color.

example : Comment background color specified in user fonts and colors settings : #FF4040 (255,64,64)
Comment background color measured with screenshot :
=> #D94040 (217,64,64) with plain text background color : black
=> #FF6666 (255,102,102) with plain text background color : white

All of these methods return #FF4040

IVsFontAndColorStorage.GetItem( PredefinedClassificationTypeNames.Comment, colorInfo );  
TextFormattingRunProperties.BackgroundBrush for IClassificationTypeRegistryService.GetClassificationType( PredefinedClassificationTypeNames.Comment );  
IVsUIShell5.GetThemedColor(ref Category, Microsoft.VisualStudio.PlatformUI.EnvironmentColors.EnvironmentBackgroundBrushKey.Name, (uint)__THEMEDCOLORTYPE.TCT_Background); for Microsoft.VisualStudio.PlatformUI.CommonDocumentColors.Category  
Microsoft.VisualStudio.Shell.VsColors.GetCurrentThemedColorValues().Keys.Where(ca => ca.Name.Contains("Comment") );	  
	  

I did not find how to use these methods :

ImageThemingUtilities.ThemePixel()  
ImageThemingUtilities.ThemePixelWithExtraContrast()  
ImageThemingUtilities.TransformLuminosity()  

I was able to find the equation of the luminance :

CommentBackgroundColorRealLuminance = CommentBackgroundColorSettingsLuminance + (( PlainTextBackgroundSettingsLuminance - CommentBackgroundColorSettingsLuminance) / 5 )  

but the saturation equation seems not linear.

I would use some help with that.
Thank you for your answers

227218-commentbackgroundcolor.png

227186-plaintextbackgroundcolor.png

227228-screenshotblack.png

227187-screenshotwhite.png

Community Center Not monitored
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.