Pick a Font (#1386)

This commit is contained in:
Jeremy Bullock 2017-09-13 04:04:05 -06:00 committed by shun-iwasawa
parent ef0db1c0bb
commit 807052a00f
11 changed files with 212 additions and 58 deletions

View file

@ -224,6 +224,11 @@ public:
return m_moveCurrentFrameByClickCellArea;
}
void setInterfaceFont(std::string font);
QString getInterfaceFont() { return m_interfaceFont; }
void setInterfaceFontWeight(int weight);
int getInterfaceFontWeight() { return m_interfaceFontWeight; }
// Visualization tab
void setShow0ThickLines(bool on);
@ -500,7 +505,7 @@ private:
QString m_units, m_cameraUnits, m_scanLevelType, m_currentRoomChoice,
m_oldUnits, m_oldCameraUnits, m_ffmpegPath, m_shortcutPreset,
m_customProjectRoot;
m_customProjectRoot, m_interfaceFont;
QString m_fastRenderPath;
double m_defLevelWidth, m_defLevelHeight, m_defLevelDpi;
@ -514,7 +519,7 @@ private:
m_chunkSize, m_blanksCount, m_onionPaperThickness, m_step, m_shrink,
m_textureSize, m_autocreationType, m_keyframeType, m_animationStep,
m_ffmpegTimeout; // seconds
int m_projectRoot, m_importPolicy;
int m_projectRoot, m_importPolicy, m_interfaceFontWeight;
QString m_currentLanguage, m_currentStyleSheet;
int m_undoMemorySize, // in megabytes
m_dragCellsBehaviour, m_lineTestFpsCapture, m_defLevelType, m_xsheetStep,

View file

@ -96,14 +96,7 @@ const char *applicationRevision = "3";
const char *dllRelativePath = "./toonz6.app/Contents/Frameworks";
#endif
#ifdef _WIN32
TEnv::StringVar EnvSoftwareCurrentFont("SoftwareCurrentFont", "Arial");
#else
TEnv::StringVar EnvSoftwareCurrentFont("SoftwareCurrentFont", "Hervetica");
#endif
TEnv::IntVar EnvSoftwareCurrentFontSize("SoftwareCurrentFontSize", 12);
TEnv::StringVar EnvSoftwareCurrentFontWeight("SoftwareCurrentFontWeightIsBold",
"Yes");
const char *applicationFullName = "OpenToonz 1.1.3";
const char *rootVarName = "TOONZROOT";
@ -371,11 +364,12 @@ int main(int argc, char *argv[]) {
splashPixmap.setDevicePixelRatio(QApplication::desktop()->devicePixelRatio());
// QPixmap splashPixmap(":Resources/splash.png");
#ifdef _WIN32
QFont font("Arial", -1);
QFont font("Segoe UI", -1);
#else
QFont font("Helvetica", -1);
#endif
font.setPixelSize(13);
font.setWeight(50);
a.setFont(font);
QString offsetStr("\n\n\n\n\n\n\n\n");
@ -640,14 +634,13 @@ int main(int argc, char *argv[]) {
}
QFont *myFont;
std::string family = EnvSoftwareCurrentFont;
myFont = new QFont(QString(family.c_str()));
std::string fontName =
Preferences::instance()->getInterfaceFont().toStdString();
std::string isBold =
Preferences::instance()->getInterfaceFontWeight() ? "Yes" : "No";
myFont = new QFont(QString::fromStdString(fontName));
myFont->setPixelSize(EnvSoftwareCurrentFontSize);
/*-- フォントのBoldの指定 --*/
std::string weight = EnvSoftwareCurrentFontWeight;
if (strcmp(weight.c_str(), "Yes") == 0)
if (strcmp(isBold.c_str(), "Yes") == 0)
myFont->setBold(true);
else
myFont->setBold(false);

View file

@ -32,6 +32,7 @@
// TnzCore includes
#include "tsystem.h"
#include "tfont.h"
// Qt includes
#include <QHBoxLayout>
@ -339,6 +340,23 @@ void PreferencesPopup::onRoomChoiceChanged(int index) {
//-----------------------------------------------------------------------------
void PreferencesPopup::onInterfaceFontChanged(int index) {
QString font = m_interfaceFont->currentText();
m_pref->setInterfaceFont(font.toStdString());
if (font.contains("Comic Sans"))
DVGui::warning(tr("Life is too short for Comic Sans"));
if (font.contains("Wingdings"))
DVGui::warning(tr("Good luck. You're on your own from here."));
}
//-----------------------------------------------------------------------------
void PreferencesPopup::onInterfaceFontWeightChanged(int index) {
m_pref->setInterfaceFontWeight(index);
}
//-----------------------------------------------------------------------------
void PreferencesPopup::onImportPolicyChanged(int index) {
m_pref->setDefaultImportPolicy(index);
}
@ -1176,6 +1194,9 @@ PreferencesPopup::PreferencesPopup()
new QLabel(tr("* Changes will take effect the next time you run Toonz"));
note_interface->setStyleSheet("font-size: 10px; font: italic;");
m_interfaceFont = new QComboBox(this);
m_interfaceFontWeight = new QComboBox(this);
//--- Visualization ------------------------------
categoryList->addItem(tr("Visualization"));
CheckBox *show0ThickLinesCB =
@ -1419,6 +1440,33 @@ PreferencesPopup::PreferencesPopup()
viewerZoomCenterComboBox->addItems(zoomCenters);
viewerZoomCenterComboBox->setCurrentIndex(m_pref->getViewerZoomCenter());
TFontManager *instance = TFontManager::instance();
bool validFonts;
try {
instance->loadFontNames();
validFonts = true;
} catch (TFontLibraryLoadingError &) {
validFonts = false;
// TMessage::error(toString(e.getMessage()));
}
if (validFonts) {
std::vector<std::wstring> names;
instance->getAllFamilies(names);
for (std::vector<std::wstring>::iterator it = names.begin();
it != names.end(); ++it)
m_interfaceFont->addItem(QString::fromStdWString(*it));
m_interfaceFont->setCurrentText(m_pref->getInterfaceFont());
}
QStringList fontStyles;
fontStyles << "Regular"
<< "Bold";
m_interfaceFontWeight->addItems(fontStyles);
m_interfaceFontWeight->setCurrentIndex(m_pref->getInterfaceFontWeight());
//--- Visualization ------------------------------
show0ThickLinesCB->setChecked(m_pref->getShow0ThickLines());
regionAntialiasCB->setChecked(m_pref->getRegionAntialias());
@ -1774,6 +1822,14 @@ PreferencesPopup::PreferencesPopup()
Qt::AlignRight | Qt::AlignVCenter);
bgColorsLay->addWidget(languageType, 7, 1, 1, 4);
}
if (m_interfaceFont->count() > 0) {
bgColorsLay->addWidget(new QLabel(tr("Font *:")), 8, 0,
Qt::AlignRight | Qt::AlignVCenter);
bgColorsLay->addWidget(m_interfaceFont, 8, 1, 1, 4);
bgColorsLay->addWidget(new QLabel(tr("Font Weight *:")), 9, 0,
Qt::AlignRight | Qt::AlignVCenter);
bgColorsLay->addWidget(m_interfaceFontWeight, 9, 1, 1, 4);
}
}
bgColorsLay->setColumnStretch(0, 0);
bgColorsLay->setColumnStretch(1, 0);
@ -2246,6 +2302,10 @@ PreferencesPopup::PreferencesPopup()
ret =
ret && connect(viewerZoomCenterComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(onViewerZoomCenterChanged(int)));
ret = ret && connect(m_interfaceFont, SIGNAL(currentIndexChanged(int)), this,
SLOT(onInterfaceFontChanged(int)));
ret = ret && connect(m_interfaceFontWeight, SIGNAL(currentIndexChanged(int)),
this, SLOT(onInterfaceFontWeightChanged(int)));
ret = ret && connect(replaceAfterSaveLevelAsCB, SIGNAL(stateChanged(int)),
this, SLOT(onReplaceAfterSaveLevelAsChanged(int)));
ret =

View file

@ -54,7 +54,7 @@ private:
QComboBox *m_keyframeType, *m_cellsDragBehaviour, *m_defScanLevelType,
*m_defLevelType, *m_autocreationType, *m_levelFormatNames,
*m_columnIconOm, *m_unitOm, *m_cameraUnitOm, *m_importPolicy,
*m_vectorSnappingTargetCB;
*m_interfaceFont, *m_interfaceFontWeight, *m_vectorSnappingTargetCB;
DVGui::MeasuredDoubleLineEdit *m_defLevelWidth, *m_defLevelHeight;
@ -184,6 +184,8 @@ private slots:
void onInputCellsWithoutDoubleClickingClicked(int);
void onShortcutCommandsWhileRenamingCellClicked(int);
void onWatchFileSystemClicked(int);
void onInterfaceFontChanged(int index);
void onInterfaceFontWeightChanged(int index);
};
//**********************************************************************************

View file

@ -514,11 +514,15 @@ void RenameCellField::showInRowCol(int row, int col, bool multiColumnSelected) {
m_row = row;
m_col = col;
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
setFont(font);
setAlignment(Qt::AlignRight | Qt::AlignBottom);
@ -633,7 +637,7 @@ void RenameCellField::renameCell() {
fid = TFrameId(fidRe.cap(1).toInt(),
fidRe.cap(2) == "" ? 0 : fidRe.cap(2).toLatin1()[0]);
#else
fid = TFrameId(fidRe.cap(1).toInt(),
fid = TFrameId(fidRe.cap(1).toInt(),
fidRe.cap(2) == "" ? 0 : fidRe.cap(2).toAscii()[0]);
#endif
FilmstripCmd::renumberDrawing(sl, cell.m_frameId, fid);
@ -1415,11 +1419,15 @@ void CellArea::drawLevelCell(QPainter &p, int row, int col, bool isReference) {
p.setPen(isRed ? m_viewer->getSelectedColumnTextColor()
: m_viewer->getTextColor());
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);
@ -1549,13 +1557,17 @@ void CellArea::drawSoundTextCell(QPainter &p, int row, int col) {
p.setPen(Qt::black);
QRect nameRect = o->rect(PredefinedRect::CELL_NAME).translated(QPoint(x, y));
// il nome va scritto se e' diverso dalla cella precedente oppure se
// siamo su una marker line
// il nome va scritto se e' diverso dalla cella precedente oppure se
// siamo su una marker line
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);
@ -1578,7 +1590,7 @@ void CellArea::drawSoundTextCell(QPainter &p, int row, int col) {
QFontMetrics metric(font);
QString elidaName = elideText(text, metric, nameRect.width(), "~");
#else
QString elidaName = elideText(text, font, nameRect.width(), "~");
QString elidaName = elideText(text, font, nameRect.width(), "~");
#endif
if (!sameLevel || prevCell.m_frameId != cell.m_frameId)
@ -1686,13 +1698,17 @@ void CellArea::drawPaletteCell(QPainter &p, int row, int col,
if (pl && !pl->getPalette()) isRed = true;
p.setPen(isRed ? m_viewer->getSelectedColumnTextColor()
: m_viewer->getTextColor());
// il nome va scritto se e' diverso dalla cella precedente oppure se
// siamo su una marker line
// il nome va scritto se e' diverso dalla cella precedente oppure se
// siamo su una marker line
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);
QFontMetrics fm(font);

View file

@ -339,11 +339,15 @@ void ChangeObjectParent::refresh() {
for (i = 0; i < columnList.size(); i++) addItem(columnList.at(i));
for (i = 0; i < pegbarList.size(); i++) addItem(pegbarList.at(i));
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Bold);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
// set font size in pixel
font.setPixelSize(XSHEET_FONT_PX_SIZE);
@ -460,11 +464,15 @@ RenameColumnField::RenameColumnField(QWidget *parent, XsheetViewer *viewer)
void RenameColumnField::show(const QRect &rect, int col) {
move(rect.topLeft());
setFixedSize(rect.size());
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
setFont(font);
m_col = col;
@ -550,12 +558,16 @@ ColumnArea::DrawHeader::DrawHeader(ColumnArea *nArea, QPainter &nP, int nCol)
}
void ColumnArea::DrawHeader::prepare() const {
// Preparing painter
// Preparing painter
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);
@ -1112,12 +1124,16 @@ void ColumnArea::drawLevelColumnHead(QPainter &p, int col) {
TColumnSelection *selection = m_viewer->getColumnSelection();
const Orientation *o = m_viewer->orientation();
// Preparing painter
// Preparing painter
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);
@ -1182,11 +1198,15 @@ void ColumnArea::drawSoundColumnHead(QPainter &p, int col) { // AREA
int x = m_viewer->columnToLayerAxis(col);
p.setRenderHint(QPainter::SmoothPixmapTransform, true);
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);
@ -1230,11 +1250,15 @@ void ColumnArea::drawPaletteColumnHead(QPainter &p, int col) { // AREA
QPoint orig = m_viewer->positionToXY(CellPosition(0, max(col, 0)));
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);
@ -1277,11 +1301,15 @@ void ColumnArea::drawSoundTextColumnHead(QPainter &p, int col) { // AREA
int x = m_viewer->columnToLayerAxis(col);
p.setRenderHint(QPainter::SmoothPixmapTransform, true);
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Normal);
font.setPixelSize(XSHEET_FONT_PX_SIZE);
p.setFont(font);

View file

@ -87,11 +87,15 @@ void RowArea::drawRows(QPainter &p, int r0, int r1) {
playR0 = 0;
}
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Bold);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Bold);
// set font size in pixel
font.setPixelSize(XSHEET_FONT_PX_SIZE);

View file

@ -224,6 +224,12 @@ Preferences::Preferences()
, m_cameraUnits("inch")
, m_currentRoomChoice("Default")
, m_scanLevelType("tif")
#ifdef _WIN32
, m_interfaceFont("Segoe UI")
#else
, m_interfaceFont("Helvetica")
#endif
, m_interfaceFontWeight(0)
, m_defLevelWidth(0.0)
, m_defLevelHeight(0.0)
, m_defLevelDpi(0.0)
@ -600,6 +606,10 @@ Preferences::Preferences()
QString shortcutPreset = m_settings->value("shortcutPreset").toString();
if (shortcutPreset != "") m_shortcutPreset = shortcutPreset;
setShortcutPreset(m_shortcutPreset.toStdString());
QString interfaceFont = m_settings->value("interfaceFont").toString();
if (interfaceFont != "") m_interfaceFont = interfaceFont;
setInterfaceFont(m_interfaceFont.toStdString());
getValue(*m_settings, "interfaceFontWeight", m_interfaceFontWeight);
getValue(*m_settings, "useNumpadForSwitchingStyles",
m_useNumpadForSwitchingStyles);
getValue(*m_settings, "newLevelSizeToCameraSizeEnabled",
@ -1209,6 +1219,20 @@ QString Preferences::getCurrentStyleSheetName() const {
//-----------------------------------------------------------------
void Preferences::setInterfaceFont(std::string font) {
m_interfaceFont = QString::fromStdString(font);
m_settings->setValue("interfaceFont", m_interfaceFont);
}
//-----------------------------------------------------------------
void Preferences::setInterfaceFontWeight(int weight) {
m_interfaceFontWeight = weight;
m_settings->setValue("interfaceFontWeight", m_interfaceFontWeight);
}
//-----------------------------------------------------------------
QString Preferences::getCurrentStyleSheetPath() const {
if (m_currentStyleSheet.isEmpty()) return QString();
TFilePath path(TEnv::getConfigDir() + "qss");

View file

@ -13,7 +13,7 @@
#include "toonz/tframehandle.h"
#include "toonz/doubleparamcmd.h"
#include "toonz/toonzfolders.h"
#include "toonz/preferences.h"
// TnzBase includes
#include "tdoubleparam.h"
#include "tdoublekeyframe.h"
@ -1067,8 +1067,17 @@ void FunctionPanel::drawGroupKeyframes(QPainter &painter) {
void FunctionPanel::paintEvent(QPaintEvent *e) {
m_gadgets.clear();
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
fontName = "Arial";
#else
fontName = "Helvetica";
#endif
}
QPainter painter(this);
QFont font("Arial", 8);
QFont font(fontName, 8);
painter.setFont(font);
QFontMetrics fm(font);

View file

@ -642,11 +642,15 @@ void FunctionSheetCellViewer::drawCells(QPainter &painter, int r0, int c0,
text.append("~");
}
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Bold);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Bold);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Bold);
font.setPixelSize(12);
painter.setFont(font);
painter.drawText(cellRect.adjusted(10, 0, 0, 0),
@ -693,11 +697,15 @@ void FunctionSheetCellViewer::mouseDoubleClickEvent(QMouseEvent *e) {
} else
m_lineEdit->setText("");
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", 9, QFont::Normal);
fontName = "Arial";
#else
static QFont font("Helvetica", 9, QFont::Normal);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, 9, QFont::Normal);
m_lineEdit->setFont(font);
m_lineEdit->setGeometry(x0 - 2, y0 - 2, x1 - x0 + 1 + 4,

View file

@ -2,6 +2,7 @@
#include "toonzqt/spreadsheetviewer.h"
#include "toonzqt/gutil.h"
#include "toonz/preferences.h"
#include "toonz/tframehandle.h"
#include "orientation.h"
@ -291,11 +292,15 @@ DragTool *RowPanel::createDragTool(QMouseEvent *) {
//-----------------------------------------------------------------------------
void RowPanel::drawRows(QPainter &p, int r0, int r1) {
QString fontName = Preferences::instance()->getInterfaceFont();
if (fontName == "") {
#ifdef _WIN32
static QFont font("Arial", -1, QFont::Bold);
fontName = "Arial";
#else
static QFont font("Helvetica", -1, QFont::Bold);
fontName = "Helvetica";
#endif
}
static QFont font(fontName, -1, QFont::Bold);
font.setPixelSize(12);
p.setFont(font);