Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(term size): add max-font-size mode 新增最大字型大小模式 #81

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/components/ContextMenu/PrefModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ export const PrefModal = ({
>
{i18n("options_fixedFontSize")}
</option>
<option
key={"options_maxFontSize"}
value={"max-font-size"}
>
{i18n("options_maxFontSize")}
</option>
</FormControl>
</FormGroup>
{(() => {
Expand Down Expand Up @@ -383,6 +389,20 @@ export const PrefModal = ({
/>
</FormGroup>
);
case "max-font-size":
return (
<FormGroup controlId="fontSize">
<ControlLabel>
{i18n("options_fontSizeMax")}
</ControlLabel>
<FormControl
name="fontSize"
type="number"
value={values.fontSize}
onChange={onNumberInputChange}
/>
</FormGroup>
);
default:
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions src/js/en_US_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ export const en_US = {
"options_fontSize": {
"message": "Font size (px)"
},
"options_fontSizeMax": {
"message": "Maximum font size (px)"
},
"options_fixedTermSize": {
"message": "Fixed term size"
},
"options_fixedFontSize": {
"message": "Fixed font size"
},
"options_maxFontSize": {
"message": "Maximum-limited font size"
},
"options_fontFitWindowWidth": {
"message": "Stretch font to fill the view"
},
Expand Down
17 changes: 17 additions & 0 deletions src/js/pttchrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,23 @@ App.prototype.onValuesPrefChange = function(values) {
// Immediately recalc once.
this.resizer();
break;

case 'max-font-size':
this.view.fontFitWindowWidth = false;

let maxFontSize = values.fontSize;
let minSize = {cols: 80, rows: 24};
this.resizer = () => {
let scaledFontSize = this.view.calcFontSizeFromTerm(minSize.cols, minSize.rows);
let fontSize = Math.min(scaledFontSize, maxFontSize);
let size = this.view.calcTermSizeFromFont(fontSize);
this.setTermSize(size.cols, size.rows);
this.view.fixedResize(fontSize);
this.view.redraw(true);
};
// Immediately recalc once.
this.resizer();
break;
}

if (this.view.fontFitWindowWidth) {
Expand Down
10 changes: 10 additions & 0 deletions src/js/term_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,16 @@ TermView.prototype = {
};
},

calcFontSizeFromTerm: function(termCols, termRows) {
termCols = Math.max(80, Math.min(200, termCols));
termRows = Math.max(24, Math.min(100, termRows));
let width = this.bbsWidth ? this.bbsWidth : this.innerBounds.width;
let height = this.bbsHeight ? this.bbsHeight : this.innerBounds.height;
let sizeX = Math.floor(2 * (width - 10) / termCols);
let sizeY = Math.floor(height / termRows);
return Math.min(sizeX, sizeY);
},

getRowLineElement: function(node) {
for (let r = node; r && r != r.parentNode; r = r.parentNode) {
if (r instanceof Element &&
Expand Down
6 changes: 6 additions & 0 deletions src/js/zh_TW_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@
"options_fontSize": {
"message": "字體大小 (px)"
},
"options_fontSizeMax": {
"message": "最大字體大小 (px)"
},
"options_fixedTermSize": {
"message": "固定終端機大小"
},
"options_fixedFontSize": {
"message": "固定字體大小"
},
"options_maxFontSize": {
"message": "限制最大字體大小"
},
"options_fontFitWindowWidth": {
"message": "把字體拉大來補滿畫面"
},
Expand Down