Allow to set custom font before starting
This commit is contained in:
		
							parent
							
								
									c68dceb189
								
							
						
					
					
						commit
						b445c55444
					
				
					 4 changed files with 43 additions and 2 deletions
				
			
		|  | @ -29,6 +29,7 @@ auto PaletteChanges = rpl::event_stream<>(); | |||
| auto ShortAnimationRunning = rpl::variable<bool>(false); | ||||
| auto RunningShortAnimations = 0; | ||||
| auto ResolvedMonospaceFont = style::font(); | ||||
| QString CustomMonospaceFont; | ||||
| 
 | ||||
| std::vector<internal::ModuleBase*> &StyleModules() { | ||||
| 	static auto result = std::vector<internal::ModuleBase*>(); | ||||
|  | @ -51,6 +52,9 @@ void ResolveMonospaceFont() { | |||
| 			family = attempt; | ||||
| 		} | ||||
| 	}; | ||||
| 	if (!CustomMonospaceFont.isEmpty()) { | ||||
| 		tryFont(CustomMonospaceFont); | ||||
| 	} | ||||
| 	tryFont("Consolas"); | ||||
| 	tryFont("Liberation Mono"); | ||||
| 	tryFont("Menlo"); | ||||
|  | @ -65,6 +69,10 @@ void ResolveMonospaceFont() { | |||
| 
 | ||||
| } // namespace
 | ||||
| 
 | ||||
| void SetMonospaceFont(const QString &familyName) { | ||||
| 	CustomMonospaceFont = familyName; | ||||
| } | ||||
| 
 | ||||
| void registerModule(ModuleBase *module) { | ||||
| 	StyleModules().push_back(module); | ||||
| } | ||||
|  |  | |||
|  | @ -25,6 +25,8 @@ public: | |||
| 
 | ||||
| }; | ||||
| 
 | ||||
| void SetMonospaceFont(const QString &familyName); | ||||
| 
 | ||||
| void registerModule(ModuleBase *module); | ||||
| 
 | ||||
| [[nodiscard]] QColor EnsureContrast(const QColor &over, const QColor &under); | ||||
|  |  | |||
|  | @ -121,8 +121,24 @@ QString FontTypeWindowsFallback[FontTypesCount] = { | |||
| bool Started = false; | ||||
| QString Overrides[FontTypesCount]; | ||||
| 
 | ||||
| QString CustomMainFont; | ||||
| QString CustomSemiboldFont; | ||||
| bool CustomSemiboldIsBold = false; | ||||
| 
 | ||||
| } // namespace
 | ||||
| 
 | ||||
| void SetMainFont(const QString &familyName) { | ||||
| 	CustomMainFont = familyName; | ||||
| } | ||||
| 
 | ||||
| void SetSemiboldFont(const QString &familyName) { | ||||
| 	CustomSemiboldFont = familyName; | ||||
| } | ||||
| 
 | ||||
| void SetSemiboldIsBold(bool isBold) { | ||||
| 	CustomSemiboldIsBold = isBold; | ||||
| } | ||||
| 
 | ||||
| void StartFonts() { | ||||
| 	if (Started) { | ||||
| 		return; | ||||
|  | @ -164,6 +180,17 @@ void StartFonts() { | |||
| 		QFont::insertSubstitutions(name, list); | ||||
| 	} | ||||
| #endif // Q_OS_MAC
 | ||||
| 
 | ||||
| 	if (!CustomMainFont.isEmpty() && ValidateFont(CustomMainFont)) { | ||||
| 		Overrides[FontTypeRegular] = CustomMainFont; | ||||
| 		Overrides[FontTypeRegularItalic] = CustomMainFont; | ||||
| 		Overrides[FontTypeBold] = CustomMainFont; | ||||
| 		Overrides[FontTypeBoldItalic] = CustomMainFont; | ||||
| 	} | ||||
| 	if (!CustomSemiboldFont.isEmpty() && ValidateFont(CustomSemiboldFont)) { | ||||
| 		Overrides[FontTypeSemibold] = CustomSemiboldFont; | ||||
| 		Overrides[FontTypeSemiboldItalic] = CustomSemiboldFont; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| QString GetPossibleEmptyOverride(const QString &familyName, int32 flags) { | ||||
|  | @ -226,8 +253,8 @@ FontData::FontData(int size, uint32 flags, int family, Font *other) | |||
| 	f.setPixelSize(size); | ||||
| 	if (_flags & FontBold) { | ||||
| 		f.setBold(true); | ||||
| 	//} else if (fontFamilies[family] == "Open Sans Semibold") {
 | ||||
| 	//	f.setWeight(QFont::DemiBold);
 | ||||
| 	} else if (fontFamilies[family] == "Open Sans Semibold" && CustomSemiboldIsBold) { | ||||
| 		f.setBold(true); | ||||
| 	} | ||||
| 	f.setItalic(_flags & FontItalic); | ||||
| 	f.setUnderline(_flags & FontUnderline); | ||||
|  |  | |||
|  | @ -14,6 +14,10 @@ | |||
| namespace style { | ||||
| namespace internal { | ||||
| 
 | ||||
| void SetMainFont(const QString &familyName); | ||||
| void SetSemiboldFont(const QString &familyName); | ||||
| void SetSemiboldIsBold(bool isBold); | ||||
| 
 | ||||
| void StartFonts(); | ||||
| [[nodiscard]] QString GetFontOverride(const QString &familyName, int32 flags = 0); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue