First round of caf::FontTools

This commit is contained in:
Gaute Lindkvist
2020-05-09 11:23:58 +02:00
parent 0e70cf809c
commit 2fe4372dc2
86 changed files with 1021 additions and 966 deletions

View File

@@ -1456,6 +1456,19 @@ cvf::Font* RiaApplication::defaultSceneFont()
return m_defaultSceneFont.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Font* RiaApplication::sceneFont( int fontSize )
{
if (fontSize != caf::FontTools::absolutePointSize(m_preferences->defaultSceneFontSize()))
{
auto font = RiaFontCache::getFont(fontSize);
return font.p();
}
return defaultSceneFont();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -188,6 +188,7 @@ public:
static std::vector<QString> readFileListFromTextFile( QString listFileName );
cvf::Font* defaultSceneFont();
cvf::Font* sceneFont(int fontSize);
cvf::Font* defaultAnnotationFont();
cvf::Font* defaultWellLabelFont();

View File

@@ -20,71 +20,70 @@
#include "RiaGuiApplication.h"
#include "cafAppEnum.h"
#include "cafFixedAtlasFont.h"
#include <QDesktopWidget>
#include <cmath>
namespace caf
{
template <>
void RiaFontCache::FontSizeType::setUp()
{
addItem( RiaFontCache::FONT_SIZE_8, "8", "8" );
addItem( RiaFontCache::FONT_SIZE_10, "10", "10" );
addItem( RiaFontCache::FONT_SIZE_12, "12", "12" );
addItem( RiaFontCache::FONT_SIZE_14, "14", "14" );
addItem( RiaFontCache::FONT_SIZE_16, "16", "16" );
addItem( RiaFontCache::FONT_SIZE_24, "24", "24" );
addItem( RiaFontCache::FONT_SIZE_32, "32", "32" );
setDefault( RiaFontCache::FONT_SIZE_8 );
}
} // namespace caf
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::FixedAtlasFont::FontSize mapToAtlasFontSize( RiaFontCache::FontSize fontSize )
caf::FixedAtlasFont::FontSize mapToAtlasFontSize( int pointSize )
{
switch ( fontSize )
{
case RiaFontCache::FONT_SIZE_8:
return caf::FixedAtlasFont::POINT_SIZE_8;
case RiaFontCache::FONT_SIZE_10:
return caf::FixedAtlasFont::POINT_SIZE_10;
case RiaFontCache::FONT_SIZE_12:
return caf::FixedAtlasFont::POINT_SIZE_12;
case RiaFontCache::FONT_SIZE_14:
return caf::FixedAtlasFont::POINT_SIZE_14;
case RiaFontCache::FONT_SIZE_16:
return caf::FixedAtlasFont::POINT_SIZE_16;
case RiaFontCache::FONT_SIZE_24:
return caf::FixedAtlasFont::POINT_SIZE_24;
case RiaFontCache::FONT_SIZE_32:
return caf::FixedAtlasFont::POINT_SIZE_32;
default:
return caf::FixedAtlasFont::POINT_SIZE_16;
}
if ( pointSize < 10 )
return caf::FixedAtlasFont::POINT_SIZE_8;
else if ( pointSize >= 10 && pointSize < 12 )
return caf::FixedAtlasFont::POINT_SIZE_10;
else if ( pointSize >= 12 && pointSize < 14 )
return caf::FixedAtlasFont::POINT_SIZE_12;
else if ( pointSize >= 14 && pointSize < 16 )
return caf::FixedAtlasFont::POINT_SIZE_14;
else if ( pointSize >= 16 && pointSize < 20 )
return caf::FixedAtlasFont::POINT_SIZE_16;
else if ( pointSize >= 20 && pointSize < 28 )
return caf::FixedAtlasFont::POINT_SIZE_24;
return caf::FixedAtlasFont::POINT_SIZE_32;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<RiaFontCache::FontSize, cvf::ref<caf::FixedAtlasFont>> RiaFontCache::ms_fonts;
std::map<caf::FixedAtlasFont::FontSize, cvf::ref<caf::FixedAtlasFont>> RiaFontCache::ms_fonts;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( FontSize size )
cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( FontSize pointFontSize )
{
if ( ms_fonts.count( size ) == 0 )
int pointSize = caf::FontTools::absolutePointSize( pointFontSize );
return getFont( pointSize );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<caf::FixedAtlasFont> RiaFontCache::getFont( int pointSize )
{
int currentDPI = 96;
if ( RiaGuiApplication::isRunning() )
{
auto newFont = new caf::FixedAtlasFont( mapToAtlasFontSize( size ) );
ms_fonts.insert( std::make_pair( size, newFont ) );
currentDPI = RiaGuiApplication::desktop()->logicalDpiX();
}
return ms_fonts[size];
// the Fixed Atlas Fonts appear to be assuming a DPI of 96, so we need scaling.
double scaling = currentDPI / 96.0;
int scaledSize = scaling * pointSize;
auto atlasFontSize = mapToAtlasFontSize( scaledSize );
auto existing_it = ms_fonts.find( atlasFontSize );
if ( existing_it == ms_fonts.end() )
{
auto newFont = new caf::FixedAtlasFont( atlasFontSize );
bool inserted = false;
std::tie( existing_it, inserted ) = ms_fonts.insert( std::make_pair( atlasFontSize, newFont ) );
CAF_ASSERT( inserted );
}
return existing_it->second;
}
//--------------------------------------------------------------------------------------------------
@@ -96,76 +95,24 @@ RiaFontCache::FontSize RiaFontCache::legacyEnumToPointSize( int enumValue )
switch ( enumValue )
{
case 0:
return FONT_SIZE_8;
return FontSize::FONT_SIZE_8;
case 1:
return FONT_SIZE_10;
return FontSize::FONT_SIZE_10;
case 2:
return FONT_SIZE_12;
return FontSize::FONT_SIZE_12;
case 3:
return FONT_SIZE_14;
return FontSize::FONT_SIZE_14;
case 4:
return FONT_SIZE_16;
return FontSize::FONT_SIZE_16;
case 5:
return FONT_SIZE_24;
return FontSize::FONT_SIZE_24;
case 6:
return FONT_SIZE_32;
return FontSize::FONT_SIZE_32;
default:
return FONT_SIZE_8;
return FontSize::FONT_SIZE_8;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaFontCache::FontSize RiaFontCache::fontSizeEnumFromPointSize( int pointSize )
{
std::vector<FontSize> allValues =
{FONT_SIZE_8, FONT_SIZE_10, FONT_SIZE_12, FONT_SIZE_14, FONT_SIZE_16, FONT_SIZE_24, FONT_SIZE_32};
FontSize closestEnumValue = FONT_SIZE_8;
int closestDiff = std::numeric_limits<int>::max();
for ( FontSize enumValue : allValues )
{
int diff = std::abs( (int)enumValue - pointSize );
if ( diff < closestDiff )
{
closestEnumValue = enumValue;
closestDiff = diff;
}
}
return closestEnumValue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaFontCache::pointSizeToPixelSize( int pointSize )
{
auto app = RiaGuiApplication::instance();
if ( app )
{
int dpi = app->desktop()->logicalDpiX();
double inches = pointSize / 72.0;
return static_cast<int>( std::ceil( inches * dpi ) );
}
return pointSize;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaFontCache::pixelSizeToPointSize( int pixelSize )
{
auto app = RiaGuiApplication::instance();
if ( app )
{
int dpi = app->desktop()->logicalDpiX();
double inches = pixelSize / dpi;
return static_cast<int>( std::ceil( inches * 72.0 ) );
}
return pixelSize;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -19,6 +19,7 @@
#pragma once
#include "cafFixedAtlasFont.h"
#include "cafFontTools.h"
#include "cvfObject.h"
@@ -38,30 +39,14 @@ class RimSummaryCaseCollection;
class RiaFontCache
{
public:
enum FontSize
{
INVALID = -1,
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
};
using FontSize = caf::FontTools::FontSize;
using FontSizeEnum = caf::FontTools::FontSizeEnum;
typedef caf::AppEnum<FontSize> FontSizeType;
static cvf::ref<caf::FixedAtlasFont> getFont( FontSize fontSize );
static cvf::ref<caf::FixedAtlasFont> getFont(FontSize fontSize);
static cvf::ref<caf::FixedAtlasFont> getFont( int pointSize );
static FontSize legacyEnumToPointSize( int enumValue );
static FontSize fontSizeEnumFromPointSize( int pointSize );
static int pointSizeToPixelSize( int pointSize );
static int pixelSizeToPointSize( int pixelSize );
static void clear();
static void clear();
private:
static std::map<FontSize, cvf::ref<caf::FixedAtlasFont>> ms_fonts;
static std::map<caf::FixedAtlasFont::FontSize, cvf::ref<caf::FixedAtlasFont>> ms_fonts;
};

View File

@@ -1393,7 +1393,8 @@ void RiaGuiApplication::onProgramExit()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreferences )
void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreferences,
const std::vector<caf::FontHolderInterface*>& defaultFontObjects )
{
if ( m_activeReservoirView && m_activeReservoirView->viewer() )
{
@@ -1418,7 +1419,10 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
m_preferences->appendClassNameToUiText() );
}
std::map<RiaDefines::FontSettingType, RiaFontCache::FontSize> fontSizes = m_preferences->defaultFontSizes();
for ( auto fontObject : defaultFontObjects )
{
fontObject->updateFonts();
}
if ( this->project() )
{
@@ -1457,13 +1461,6 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
existingViewsWithCustomZScale = true;
}
RimGridView* gridView = dynamic_cast<RimGridView*>( rim3dView );
if ( gridView && gridView->annotationCollection() )
{
RiaFontCache::FontSize oldFontSize = oldPreferences->defaultAnnotationFontSize();
existingObjectsWithCustomFonts =
gridView->annotationCollection()->hasTextAnnotationsWithCustomFontSize( oldFontSize );
}
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>( rim3dView );
if ( eclipseView )
{
@@ -1475,18 +1472,6 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
}
}
}
for ( auto fontTypeSizePair : fontSizes )
{
RiaFontCache::FontSize oldFontSize = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
if ( oldFontSize != fontTypeSizePair.second )
{
if ( viewWindow->hasCustomFontSizes( fontTypeSizePair.first, oldFontSize ) )
{
existingObjectsWithCustomFonts = true;
}
}
}
}
if ( oldPreferences->defaultWellLabelColor() != wellPathCollection->wellPathLabelColor() )
@@ -1525,16 +1510,6 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences* oldPreference
for ( auto viewWindow : allViewWindows )
{
for ( auto fontTypeSizePair : fontSizes )
{
RiaFontCache::FontSize oldFontSize = oldPreferences->defaultFontSizes()[fontTypeSizePair.first];
int newFontSize = fontTypeSizePair.second;
if ( oldFontSize != newFontSize )
{
viewWindow->applyFontSize( fontTypeSizePair.first, oldFontSize, newFontSize, applySettingsToAllViews );
}
}
auto rim3dView = dynamic_cast<Rim3dView*>( viewWindow );
if ( rim3dView )
{

View File

@@ -66,6 +66,11 @@ class RiuPlotMainWindow;
class RiuRecentFileActionProvider;
class RiaArgumentParser;
namespace caf
{
class FontHolderInterface;
}
//==================================================================================================
//
//
@@ -123,7 +128,8 @@ public:
std::vector<QAction*> recentFileActions() const;
static void clearAllSelections();
void applyGuiPreferences( const RiaPreferences* oldPreferences = nullptr );
void applyGuiPreferences( const RiaPreferences* oldPreferences = nullptr,
const std::vector<caf::FontHolderInterface*>& defaultFontObjects = {} );
void updateGrpcServer();
static int applicationResolution();

View File

@@ -179,12 +179,10 @@ RiaPreferences::RiaPreferences( void )
CAF_PDM_InitField( &m_defaultScaleFactorZ, "defaultScaleFactorZ", 5, "Default Z Scale Factor", "", "", "" );
caf::AppEnum<RiaFontCache::FontSize> fontSize = RiaFontCache::FONT_SIZE_8;
caf::AppEnum<RiaFontCache::FontSize> plotFontSize = RiaFontCache::FONT_SIZE_10;
CAF_PDM_InitField( &defaultSceneFontSize, "defaultSceneFontSizePt", fontSize, "Viewer Font Size", "", "", "" );
CAF_PDM_InitField( &defaultAnnotationFontSize, "defaultAnnotationFontSizePt", fontSize, "Annotation Font Size", "", "", "" );
CAF_PDM_InitField( &defaultWellLabelFontSize, "defaultWellLabelFontSizePt", fontSize, "Well Label Font Size", "", "", "" );
CAF_PDM_InitField( &defaultPlotFontSize, "defaultPlotFontSizePt", plotFontSize, "Plot Font Size", "", "", "" );
CAF_PDM_InitFieldNoDefault( &defaultSceneFontSize, "defaultSceneFontSizePt", "Viewer Font Size", "", "", "" );
CAF_PDM_InitFieldNoDefault( &defaultAnnotationFontSize, "defaultAnnotationFontSizePt", "Annotation Font Size", "", "", "" );
CAF_PDM_InitFieldNoDefault( &defaultWellLabelFontSize, "defaultWellLabelFontSizePt", "Well Label Font Size", "", "", "" );
CAF_PDM_InitFieldNoDefault( &defaultPlotFontSize, "defaultPlotFontSizePt", "Plot Font Size", "", "", "" );
CAF_PDM_InitField( &showLasCurveWithoutTvdWarning,
"showLasCurveWithoutTvdWarning",
@@ -369,31 +367,6 @@ RiaPreferences::RiaPreferences( void )
CAF_PDM_InitField( &m_pageRightMargin, "pageRightMargin", defaultMarginSize( m_pageSize() ), "Right Margin", "", "", "" );
CAF_PDM_InitField( &m_pageBottomMargin, "pageBottomMargin", defaultMarginSize( m_pageSize() ), "Bottom Margin", "", "", "" );
caf::AppEnum<RiaFontCache::FontSize> invalidFontSize = RiaFontCache::INVALID;
CAF_PDM_InitField( &m_defaultSceneFontSize_OBSOLETE, "fontSizeInScene", invalidFontSize, "Viewer Font Size", "", "", "" );
m_defaultSceneFontSize_OBSOLETE.xmlCapability()->setIOWritable( false );
CAF_PDM_InitField( &m_defaultAnnotationFontSize_OBSOLETE,
"defaultAnnotationFontSize",
invalidFontSize,
"Annotation Font Size",
"",
"",
"" );
m_defaultAnnotationFontSize_OBSOLETE.xmlCapability()->setIOWritable( false );
CAF_PDM_InitField( &m_defaultWellLabelFontSize_OBSOLETE,
"wellLabelFontSize",
invalidFontSize,
"Well Label Font Size",
"",
"",
"" );
m_defaultWellLabelFontSize_OBSOLETE.xmlCapability()->setIOWritable( false );
CAF_PDM_InitField( &m_defaultPlotFontSize_OBSOLETE, "defaultPlotFontSize", invalidFontSize, "Plot Font Size", "", "", "" );
m_defaultPlotFontSize_OBSOLETE.xmlCapability()->setIOWritable( false );
CAF_PDM_InitField( &m_openExportedPdfInViewer, "openExportedPdfInViewer", false, "Open Exported PDF in Viewer", "", "", "" );
m_openExportedPdfInViewer.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
}
@@ -668,27 +641,6 @@ QList<caf::PdmOptionItemInfo> RiaPreferences::calculateValueOptions( const caf::
//--------------------------------------------------------------------------------------------------
void RiaPreferences::initAfterRead()
{
// 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>( m_defaultSceneFontSize_OBSOLETE.v() );
if ( defaultSceneFontEnumValue >= (int)RiaFontCache::MIN_FONT_SIZE )
{
defaultSceneFontSize = RiaFontCache::legacyEnumToPointSize( defaultSceneFontEnumValue );
}
int defaultWellLabelFontEnumValue = static_cast<int>( m_defaultWellLabelFontSize_OBSOLETE.v() );
if ( defaultWellLabelFontEnumValue >= (int)RiaFontCache::MIN_FONT_SIZE )
{
defaultWellLabelFontSize = RiaFontCache::legacyEnumToPointSize( defaultWellLabelFontEnumValue );
}
int defaultAnnotationFontEnumValue = static_cast<int>( m_defaultAnnotationFontSize_OBSOLETE.v() );
if ( defaultAnnotationFontEnumValue >= (int)RiaFontCache::MIN_FONT_SIZE )
{
defaultAnnotationFontSize = RiaFontCache::legacyEnumToPointSize( defaultAnnotationFontEnumValue );
}
int defaultPlotFontEnumValue = static_cast<int>( m_defaultPlotFontSize_OBSOLETE.v() );
if ( defaultPlotFontEnumValue >= (int)RiaFontCache::MIN_FONT_SIZE )
{
defaultPlotFontSize = RiaFontCache::legacyEnumToPointSize( defaultPlotFontEnumValue );
}
}
//--------------------------------------------------------------------------------------------------

View File

@@ -56,7 +56,7 @@ public:
SEPARATE_CASES
};
typedef caf::AppEnum<SummaryRestartFilesImportMode> SummaryRestartFilesImportModeType;
typedef RiaFontCache::FontSizeType FontSizeType;
typedef RiaFontCache::FontSizeEnum FontSizeEnum;
enum class SummaryHistoryCurveStyleMode
{
@@ -139,10 +139,10 @@ public: // Pdm Fields
caf::PdmField<cvf::Color3f> defaultWellLabelColor;
caf::PdmField<bool> showLasCurveWithoutTvdWarning;
caf::PdmField<FontSizeType> defaultSceneFontSize;
caf::PdmField<FontSizeType> defaultWellLabelFontSize;
caf::PdmField<FontSizeType> defaultAnnotationFontSize;
caf::PdmField<FontSizeType> defaultPlotFontSize;
caf::PdmField<FontSizeEnum> defaultSceneFontSize;
caf::PdmField<FontSizeEnum> defaultWellLabelFontSize;
caf::PdmField<FontSizeEnum> defaultAnnotationFontSize;
caf::PdmField<FontSizeEnum> defaultPlotFontSize;
caf::PdmField<QString> lastUsedProjectFileName;
@@ -220,9 +220,4 @@ private:
caf::PdmField<bool> m_enableFaultsByDefault;
QStringList m_tabNames;
caf::PdmField<FontSizeType> m_defaultSceneFontSize_OBSOLETE;
caf::PdmField<FontSizeType> m_defaultWellLabelFontSize_OBSOLETE;
caf::PdmField<FontSizeType> m_defaultAnnotationFontSize_OBSOLETE;
caf::PdmField<FontSizeType> m_defaultPlotFontSize_OBSOLETE;
};