diff --git a/app/FontPixels.qml b/app/FontPixels.qml new file mode 100644 index 0000000..33475bd --- /dev/null +++ b/app/FontPixels.qml @@ -0,0 +1,51 @@ +import QtQuick 2.0 + +Item{ + property int selectedFontIndex + property int selectedScalingIndex + property alias fontlist: fontlist + property var _font: fontlist.get(selectedFontIndex) + property var _scaling: fontScalingList[selectedScalingIndex] + property var source: _font.source + property var fontScalingList: [0.75, 1.0, 1.25, 1.50, 1.75, 2.0] + property int pixelSize: _font.pixelSize * _scaling + property int lineSpacing: (_font.pixelSize / _font.virtualCharHeight) * _font.lineSpacing + property size virtualCharSize: Qt.size(_font.virtualCharWidth, + _font.virtualCharHeight) + + ListModel{ + id: fontlist + ListElement{ + text: "Commodore PET (1977)" + source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" + lineSpacing: 2 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + ListElement{ + text: "Apple ][ (1977)" + source: "fonts/1977-apple2/PrintChar21.ttf" + lineSpacing: 2 + virtualCharWidth: 7 + virtualCharHeight: 8 + pixelSize: 32 + } + ListElement{ + text: "Atari 400-800 (1979)" + source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" + lineSpacing: 3 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + ListElement{ + text: "Commodore 64 (1982)" + source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" + lineSpacing: 3 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + } +} diff --git a/app/FontScanlines.qml b/app/FontScanlines.qml new file mode 100644 index 0000000..6446031 --- /dev/null +++ b/app/FontScanlines.qml @@ -0,0 +1,59 @@ +import QtQuick 2.0 + +Item{ + property int selectedFontIndex + property int selectedScalingIndex + property alias fontlist: fontlist + property var _font: fontlist.get(selectedFontIndex) + property var _scaling: fontScalingList[selectedScalingIndex] + property var source: _font.source + property var fontScalingList: [0.75, 1.0, 1.25, 1.50, 1.75, 2.0] + property int pixelSize: _font.pixelSize * _scaling + property int lineSpacing: (_font.pixelSize / _font.virtualCharHeight) * _font.lineSpacing + property size virtualCharSize: Qt.size(_font.virtualCharWidth, + _font.virtualCharHeight) + + ListModel{ + id: fontlist + ListElement{ + text: "Commodore PET (1977)" + source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" + lineSpacing: 2 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + ListElement{ + text: "Commodore PET 2Y (1977)" + source: "fonts/1977-commodore-pet/COMMODORE_PET_2y.ttf" + lineSpacing: 2 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + ListElement{ + text: "Apple ][ (1977)" + source: "fonts/1977-apple2/PrintChar21.ttf" + lineSpacing: 2 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + ListElement{ + text: "Atari 400-800 (1979)" + source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" + lineSpacing: 3 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + ListElement{ + text: "Commodore 64 (1982)" + source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" + lineSpacing: 3 + virtualCharWidth: 8 + virtualCharHeight: 8 + pixelSize: 32 + } + } +} diff --git a/app/Fonts.qml b/app/Fonts.qml new file mode 100644 index 0000000..64dbdb7 --- /dev/null +++ b/app/Fonts.qml @@ -0,0 +1,67 @@ +import QtQuick 2.0 + +Item{ + property int selectedFontIndex + property int selectedScalingIndex + property alias fontlist: fontlist + property var source: fontlist.get(selectedFontIndex).source + property var _font: fontlist.get(selectedFontIndex) + property var _scaling: fontScalingList[selectedScalingIndex] + property var fontScalingList: [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0] + property int pixelSize: _font.pixelSize * _scaling + property int lineSpacing: pixelSize * _font.lineSpacing + + //In this configuration lineSpacing is proportional to pixelSize. + + ListModel{ + id: fontlist + ListElement{ + text: "Terminus (Modern)" + source: "fonts/modern-terminus/TerminusTTF-Bold-4.38.2.ttf" + lineSpacing: 0.2 + pixelSize: 35 + } + ListElement{ + text: "Commodore PET (1977)" + source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" + lineSpacing: 0.2 + pixelSize: 24 + } + ListElement{ + text: "Commodore PET 2Y (1977)" + source: "fonts/1977-commodore-pet/COMMODORE_PET_2y.ttf" + lineSpacing: 0.2 + pixelSize: 32 + } + ListElement{ + text: "Apple ][ (1977)" + source: "fonts/1977-apple2/PrintChar21.ttf" + lineSpacing: 0.2 + pixelSize: 24 + } + ListElement{ + text: "Atari 400-800 (1979)" + source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" + lineSpacing: 0.3 + pixelSize: 24 + } + ListElement{ + text: "Commodore 64 (1982)" + source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" + lineSpacing: 0.3 + pixelSize: 24 + } + ListElement{ + text: "Atari ST (1985)" + source: "fonts/1985-atari-st/AtariST8x16SystemFont.ttf" + lineSpacing: 0.2 + pixelSize: 32 + } + ListElement{ + text: "IBM DOS (1985)" + source: "fonts/1985-ibm-pc-vga/Perfect DOS VGA 437.ttf" + lineSpacing: 0.2 + pixelSize: 32 + } + } +} diff --git a/app/SettingsWindow.qml b/app/SettingsWindow.qml index 4d816f7..b2b1d84 100644 --- a/app/SettingsWindow.qml +++ b/app/SettingsWindow.qml @@ -89,16 +89,16 @@ Window { Text{text: qsTr("Font style:")} ComboBox{ Layout.fillWidth: true - model: shadersettings.fonts_list - currentIndex: shadersettings.font_index - onCurrentIndexChanged: shadersettings.font_index = currentIndex + model: shadersettings.fontlist + currentIndex: shadersettings.fontIndex + onCurrentIndexChanged: shadersettings.fontIndex = currentIndex } Text{text: qsTr("Font scaling:")} ComboBox{ Layout.fillWidth: true - model: shadersettings._font_scalings - currentIndex: shadersettings.font_scaling_index - onCurrentIndexChanged: shadersettings.font_scaling_index = currentIndex + model: shadersettings.fontScalingList + currentIndex: shadersettings.fontScalingIndex + onCurrentIndexChanged: shadersettings.fontScalingIndex = currentIndex } Item{Layout.fillHeight: true} ColorButton{ diff --git a/app/ShaderSettings.qml b/app/ShaderSettings.qml index 679d173..1fc2036 100644 --- a/app/ShaderSettings.qml +++ b/app/ShaderSettings.qml @@ -70,6 +70,7 @@ Item{ readonly property int pixel_rasterization: 2 property int rasterization: no_rasterization + onRasterizationChanged: handleFontChanged() property string frame_source: frames_list.get(frames_index).source property int frames_index: 1 @@ -77,10 +78,56 @@ Item{ signal terminalFontChanged - property var _font_scalings: [0.5, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0] - property var font: currentfont - property int font_index: 0 - property var fonts_list: fontlist + Loader{ + id: fontManager + onSourceChanged: console.log(source) + + states: [ + State { when: rasterization == no_rasterization + PropertyChanges {target: fontManager; source: "Fonts.qml" } }, + State { when: rasterization == scanline_rasterization + PropertyChanges {target: fontManager; source: "FontScanlines.qml" } }, + State { when: rasterization == pixel_rasterization; + PropertyChanges {target: fontManager; source: "FontPixels.qml" } } + ] + + onLoaded: handleFontChanged() + } + + Text{id: fontMetrics; text: "B"; visible: false} + + FontLoader{ + property int pixelSize + property real lineSpacing + property size paintedSize + property size virtualCharSize + id: currentfont + source: fontlist.get(fontIndex).source + } + + property var fontlist: fontManager.item.fontlist + property var fontScalingList: fontManager.item.fontScalingList + property alias font: currentfont + property int fontIndex: 0 + property int fontScalingIndex: 0 + + onFontIndexChanged: {fontManager.item.selectedFontIndex = fontIndex; handleFontChanged()} + onFontScalingIndexChanged: {fontManager.item.selectedScalingIndex = fontScalingIndex; handleFontChanged()} + + function handleFontChanged(){ + currentfont.source = fontManager.item.source; + currentfont.pixelSize = fontManager.item.pixelSize; + currentfont.lineSpacing = fontManager.item.lineSpacing; + fontMetrics.font = currentfont.name; + fontMetrics.font.pixelSize = currentfont.pixelSize; + currentfont.paintedSize = Qt.size(fontMetrics.paintedWidth, fontMetrics.paintedHeight) + console.log(Qt.size(fontMetrics.paintedWidth, fontMetrics.paintedHeight)) + currentfont.virtualCharSize = fontManager.item.virtualCharSize !== undefined ? + fontManager.item.virtualCharSize : + Qt.size(currentfont.paintedSize.width * 0.5, + currentfont.paintedSize.height * 0.5); + terminalFontChanged(); + } property bool frame_reflections: true property real frame_reflection_strength: ((frame_reflections && framelist.get(frames_index).reflections) ? 1.0 : 0.0) * 0.15 @@ -89,28 +136,6 @@ Item{ property int profiles_index: 0 onProfiles_indexChanged: loadProfile(profiles_index); - onFont_indexChanged: handleFontChanged(); - onFont_scaling_indexChanged: handleFontChanged(); - - function handleFontChanged(){ - var f = fontlist.get(font_index); - var metrics = f.metrics.get(font_scaling_index); - currentfont.source = f.source; - currentfont.pixelSize = metrics.pixelSize; - currentfont.lineSpacing = f.lineSpacing; - currentfont.virtualResolution = Qt.size(metrics.virtualWidth, - metrics.virtualHeight); - terminalFontChanged(); - } - - FontLoader{ - property int pixelSize - property real lineSpacing - property size virtualResolution - id: currentfont - source: fontlist.get(font_index).source - } - ListModel{ id: framelist ListElement{text: "No frame"; source: "./frames/NoFrame.qml"; reflections: false} @@ -118,115 +143,6 @@ Item{ ListElement{text: "Rough black frame"; source: "./frames/BlackRoughFrame.qml"; reflections: true} } - property int font_scaling_index: 0 - ListModel{ - id: fontlist - ListElement{ - text: "Terminus (Modern)" - source: "fonts/modern-terminus/TerminusTTF-Bold-4.38.2.ttf" - lineSpacing: 2 - metrics: [ - ListElement{pixelSize: 18; virtualWidth: 0; virtualHeight: 6}, - ListElement{pixelSize: 24; virtualWidth: 0; virtualHeight: 8}, - ListElement{pixelSize: 35; virtualWidth: 5; virtualHeight: 12}, - ListElement{pixelSize: 43; virtualWidth: 6; virtualHeight: 11}, - ListElement{pixelSize: 54; virtualWidth: 7; virtualHeight: 11}, - ListElement{pixelSize: 64; virtualWidth: 8; virtualHeight: 11}, - ListElement{pixelSize: 75; virtualWidth: 8; virtualHeight: 11}] - } - ListElement{ - text: "Commodore PET (1977)" - source: "fonts/1977-commodore-pet/COMMODORE_PET.ttf" - lineSpacing: 2 - metrics: [ - ListElement{pixelSize: 11; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 17; virtualWidth: 0; virtualHeight: 6}, - ListElement{pixelSize: 24; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 32; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 40; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 48; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 56; virtualWidth: 8; virtualHeight: 8}] - } - ListElement{ - text: "Commodore PET 2Y (1977)" - source: "fonts/1977-commodore-pet/COMMODORE_PET_2y.ttf" - lineSpacing: 2 - metrics: [ - ListElement{pixelSize: 11; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 17; virtualWidth: 0; virtualHeight: 6}, - ListElement{pixelSize: 32; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 40; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 48; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 56; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 64; virtualWidth: 4; virtualHeight: 8}] - } - ListElement{ - text: "Apple ][ (1977)" - source: "fonts/1977-apple2/PrintChar21.ttf" - lineSpacing: 2 - metrics: [ - ListElement{pixelSize: 11; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 17; virtualWidth: 0; virtualHeight: 6}, - ListElement{pixelSize: 24; virtualWidth: 7; virtualHeight: 8}, - ListElement{pixelSize: 32; virtualWidth: 7; virtualHeight: 8}, - ListElement{pixelSize: 40; virtualWidth: 7; virtualHeight: 8}, - ListElement{pixelSize: 48; virtualWidth: 7; virtualHeight: 8}, - ListElement{pixelSize: 56; virtualWidth: 7; virtualHeight: 8}] - } - ListElement{ - text: "Atari 400-800 (1979)" - source: "fonts/1979-atari-400-800/ATARI400800_original.TTF" - lineSpacing: 3 - metrics: [ - ListElement{pixelSize: 11; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 17; virtualWidth: 0; virtualHeight: 6}, - ListElement{pixelSize: 24; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 32; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 40; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 48; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 56; virtualWidth: 8; virtualHeight: 8}] - } - ListElement{ - text: "Commodore 64 (1982)" - source: "fonts/1982-commodore64/C64_User_Mono_v1.0-STYLE.ttf" - lineSpacing: 3 - metrics: [ - ListElement{pixelSize: 11; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 17; virtualWidth: 0; virtualHeight: 6}, - ListElement{pixelSize: 24; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 32; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 40; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 48; virtualWidth: 8; virtualHeight: 8}, - ListElement{pixelSize: 56; virtualWidth: 8; virtualHeight: 8}] - } - ListElement{ - text: "Atari ST (1985)" - source: "fonts/1985-atari-st/AtariST8x16SystemFont.ttf" - lineSpacing: 2 - metrics: [ - ListElement{pixelSize: 16; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 23; virtualWidth: 0; virtualHeight: 7}, - ListElement{pixelSize: 32; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 40; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 48; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 56; virtualWidth: 4; virtualHeight: 8}, - ListElement{pixelSize: 64; virtualWidth: 8; virtualHeight: 16}] - } - ListElement{ - text: "IBM DOS (1985)" - source: "fonts/1985-ibm-pc-vga/Perfect DOS VGA 437.ttf" - lineSpacing: 2 - metrics: [ - ListElement{pixelSize: 18; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 25; virtualWidth: 0; virtualHeight: 0}, - ListElement{pixelSize: 32; virtualWidth: 6; virtualHeight: 8}, - ListElement{pixelSize: 36; virtualWidth: 6; virtualHeight: 12}, - ListElement{pixelSize: 48; virtualWidth: 9; virtualHeight: 16}, - ListElement{pixelSize: 56; virtualWidth: 9; virtualHeight: 16}, - ListElement{pixelSize: 64; virtualWidth: 9; virtualHeight: 16}] - } - } - Storage{id: storage} function composeSettingsString(){ @@ -297,7 +213,7 @@ Item{ fps = settings.fps !== undefined ? settings.fps: fps window_scaling = settings.window_scaling ? settings.window_scaling : window_scaling - font_scaling_index = settings.font_scaling_index !== undefined ? settings.font_scaling_index: font_scaling_index; + //font_scaling_index = settings.font_scaling_index !== undefined ? settings.font_scaling_index: font_scaling_index; } function loadProfileString(profileString){ @@ -317,7 +233,7 @@ Item{ frames_index = settings.frames_index !== undefined ? settings.frames_index : frames_index; - font_index = settings.font_index !== undefined ? settings.font_index : font_index; + //font_index = settings.font_index !== undefined ? settings.font_index : font_index; rasterization = settings.rasterization !== undefined ? settings.rasterization : rasterization; diff --git a/app/Terminal.qml b/app/Terminal.qml index 9c6b9c7..7f9e912 100644 --- a/app/Terminal.qml +++ b/app/Terminal.qml @@ -44,9 +44,8 @@ Item{ property real _minBlurCoefficient: 0.75 property real _maxBlurCoefficient: 0.95 - property real scanlineWidth: 1 - property real scanlineHeight: 1 - property size virtual_resolution: Qt.size(width / scanlineWidth, height / scanlineHeight) + property size virtualPxSize: Qt.size(1,1) + property size virtual_resolution: Qt.size(width / virtualPxSize.width, height / virtualPxSize.height) property real deltay: 0.5 / virtual_resolution.height property real deltax: 0.5 / virtual_resolution.width @@ -91,33 +90,28 @@ Item{ } } - Text{id: fontMetrics; text: "B"; visible: false} - function handleFontChange(){ - var scaling_factor = shadersettings.window_scaling; - var font_size = shadersettings.font.pixelSize * scaling_factor; + var newFont = shadersettings.font; + var font_size = newFont.pixelSize * shadersettings.window_scaling; font.pixelSize = font_size; - font.family = shadersettings.font.name; + font.family = newFont.name; - fontMetrics.font = font; - - var vertical_density = shadersettings.font.virtualResolution.height; - var horizontal_density = shadersettings.font.virtualResolution.width; - - var scanline_height = fontMetrics.paintedHeight / vertical_density; - var scanline_width = fontMetrics.paintedWidth / horizontal_density; + var virtualCharSize = newFont.virtualCharSize; + var virtualPxSize = Qt.size(newFont.paintedSize.width / virtualCharSize.width, + newFont.paintedSize.height / virtualCharSize.height) var scanline_spacing = shadersettings.font.lineSpacing; - var line_spacing = Math.round(scanline_spacing * scanline_height); + var line_spacing = Math.round(scanline_spacing); + + console.log(kterminal.paintedFontSize) // console.log("Font height: " + fontMetrics.paintedHeight) // console.log("Scanline Height: " + scanline_height) // console.log("Line Spacing: " + line_spacing) - terminalContainer.scanlineHeight = scanline_height; - terminalContainer.scanlineWidth = scanline_width; + terminalContainer.virtualPxSize = virtualPxSize; - setLineSpacing(line_spacing); + setLineSpacing(newFont.lineSpacing); restartBlurredSource(); } Component.onCompleted: { diff --git a/app/app.qmlproject.user b/app/app.qmlproject.user index 50ee390..4eaaea6 100644 --- a/app/app.qmlproject.user +++ b/app/app.qmlproject.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/konsole-qml-plugin/src/TerminalDisplay.cpp b/konsole-qml-plugin/src/TerminalDisplay.cpp index ae5391a..e350b8c 100644 --- a/konsole-qml-plugin/src/TerminalDisplay.cpp +++ b/konsole-qml-plugin/src/TerminalDisplay.cpp @@ -416,6 +416,9 @@ void KTerminalDisplay::setVTFont(const QFont& f) // Disabling kerning saves some computation when rendering text. font.setKerning(false); + // Konsole cannot handle non-integer font metrics + font.setStyleStrategy(QFont::StyleStrategy(font.styleStrategy() | QFont::ForceIntegerMetrics)); + //QWidget::setFont(font); m_font = font; fontChange(font);