mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Improved font handling
This commit is contained in:
@@ -83,28 +83,29 @@ cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( FontSize size )
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// In the 2019 releases the font size was stored as an enum value rather than actual size
|
||||
/// Use this method for legacy conversion
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaFontCache::pointSizeFromFontSizeEnum( FontSize fontSize )
|
||||
RiaFontCache::FontSize RiaFontCache::legacyEnumToPointSize( int enumValue )
|
||||
{
|
||||
switch ( fontSize )
|
||||
switch ( enumValue )
|
||||
{
|
||||
case RiaFontCache::FONT_SIZE_8:
|
||||
return 8;
|
||||
case RiaFontCache::FONT_SIZE_10:
|
||||
return 10;
|
||||
case RiaFontCache::FONT_SIZE_12:
|
||||
return 12;
|
||||
case RiaFontCache::FONT_SIZE_14:
|
||||
return 14;
|
||||
case RiaFontCache::FONT_SIZE_16:
|
||||
return 16;
|
||||
case RiaFontCache::FONT_SIZE_24:
|
||||
return 24;
|
||||
case RiaFontCache::FONT_SIZE_32:
|
||||
return 32;
|
||||
case 0:
|
||||
return FONT_SIZE_8;
|
||||
case 1:
|
||||
return FONT_SIZE_10;
|
||||
case 2:
|
||||
return FONT_SIZE_12;
|
||||
case 3:
|
||||
return FONT_SIZE_14;
|
||||
case 4:
|
||||
return FONT_SIZE_16;
|
||||
case 5:
|
||||
return FONT_SIZE_24;
|
||||
case 6:
|
||||
return FONT_SIZE_32;
|
||||
default:
|
||||
return 16;
|
||||
return FONT_SIZE_8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +121,11 @@ RiaFontCache::FontSize RiaFontCache::fontSizeEnumFromPointSize( int pointSize )
|
||||
int closestDiff = std::numeric_limits<int>::max();
|
||||
for ( FontSize enumValue : allValues )
|
||||
{
|
||||
int diff = std::abs( pointSizeFromFontSizeEnum( enumValue ) - pointSize );
|
||||
int diff = std::abs( (int)enumValue - pointSize );
|
||||
if ( diff < closestDiff )
|
||||
{
|
||||
closestEnumValue = enumValue;
|
||||
closestDiff = diff;
|
||||
closestDiff;
|
||||
}
|
||||
}
|
||||
return closestEnumValue;
|
||||
|
||||
@@ -40,20 +40,21 @@ class RiaFontCache
|
||||
public:
|
||||
enum FontSize
|
||||
{
|
||||
FONT_SIZE_8,
|
||||
FONT_SIZE_10,
|
||||
FONT_SIZE_12,
|
||||
FONT_SIZE_14,
|
||||
FONT_SIZE_16,
|
||||
FONT_SIZE_24,
|
||||
FONT_SIZE_32,
|
||||
MIN_FONT_SIZE = 8,
|
||||
FONT_SIZE_8 = 8,
|
||||
FONT_SIZE_10 = 10,
|
||||
FONT_SIZE_12 = 12,
|
||||
FONT_SIZE_14 = 14,
|
||||
FONT_SIZE_16 = 16,
|
||||
FONT_SIZE_24 = 24,
|
||||
FONT_SIZE_32 = 32,
|
||||
MAX_FONT_SIZE = FONT_SIZE_32
|
||||
};
|
||||
|
||||
typedef caf::AppEnum<FontSize> FontSizeType;
|
||||
|
||||
static cvf::ref<caf::FixedAtlasFont> getFont( FontSize fontSize );
|
||||
static int pointSizeFromFontSizeEnum( FontSize fontSize );
|
||||
static FontSize legacyEnumToPointSize( int enumValue );
|
||||
static FontSize fontSizeEnumFromPointSize( int pointSize );
|
||||
|
||||
static void clear();
|
||||
|
||||
@@ -1605,10 +1605,9 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
|
||||
|
||||
for ( auto fontTypeSizePair : fontSizes )
|
||||
{
|
||||
RiaFontCache::FontSize oldFontSizeEnum = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
if ( oldFontSizeEnum != fontTypeSizePair.second )
|
||||
RiaFontCache::FontSize oldFontSize = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
if ( oldFontSize != fontTypeSizePair.second )
|
||||
{
|
||||
int oldFontSize = RiaFontCache::pointSizeFromFontSizeEnum( oldFontSizeEnum );
|
||||
if ( viewWindow->hasCustomFontSizes( fontTypeSizePair.first, oldFontSize ) )
|
||||
{
|
||||
existingObjectsWithCustomFonts = true;
|
||||
@@ -1656,11 +1655,10 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
|
||||
{
|
||||
for ( auto fontTypeSizePair : fontSizes )
|
||||
{
|
||||
RiaFontCache::FontSize oldFontSizeEnum = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
if ( oldFontSizeEnum != fontTypeSizePair.second )
|
||||
RiaFontCache::FontSize oldFontSize = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
|
||||
int newFontSize = fontTypeSizePair.second;
|
||||
if ( oldFontSize != newFontSize )
|
||||
{
|
||||
int oldFontSize = RiaFontCache::pointSizeFromFontSizeEnum( oldFontSizeEnum );
|
||||
int newFontSize = RiaFontCache::pointSizeFromFontSizeEnum( fontTypeSizePair.second );
|
||||
viewWindow->applyFontSize( fontTypeSizePair.first, oldFontSize, newFontSize, applySettingsToAllViews );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,11 +628,26 @@ QList<caf::PdmOptionItemInfo> RiaPreferences::calculateValueOptions( const caf::
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPreferences::initAfterRead()
|
||||
{
|
||||
// If the stored font size is larger than the maximum enum value, the stored font size is actually point size
|
||||
// If the stored font size is smaller than the minimum enum value, the stored font size is actually just an enum value
|
||||
int defaultSceneFontEnumValue = static_cast<int>( defaultSceneFontSize.v() );
|
||||
if ( defaultSceneFontEnumValue > (int)RiaFontCache::MAX_FONT_SIZE )
|
||||
if ( defaultSceneFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultSceneFontSize = RiaFontCache::fontSizeEnumFromPointSize( defaultSceneFontEnumValue );
|
||||
defaultSceneFontSize = RiaFontCache::legacyEnumToPointSize( defaultSceneFontEnumValue );
|
||||
}
|
||||
int defaultWellLabelFontEnumValue = static_cast<int>( defaultWellLabelFontSize.v() );
|
||||
if ( defaultWellLabelFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultWellLabelFontSize = RiaFontCache::legacyEnumToPointSize( defaultWellLabelFontEnumValue );
|
||||
}
|
||||
int defaultAnnotationFontEnumValue = static_cast<int>( defaultAnnotationFontSize.v() );
|
||||
if ( defaultAnnotationFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultAnnotationFontSize = RiaFontCache::legacyEnumToPointSize( defaultAnnotationFontEnumValue );
|
||||
}
|
||||
int defaultPlotFontEnumValue = static_cast<int>( defaultPlotFontSize.v() );
|
||||
if ( defaultPlotFontEnumValue < (int)RiaFontCache::MIN_FONT_SIZE )
|
||||
{
|
||||
defaultPlotFontSize = RiaFontCache::legacyEnumToPointSize( defaultPlotFontEnumValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user