Skip to content

Commit

Permalink
add files for bold, italic, boldItalic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sodastream11 committed Jan 27, 2025
1 parent a3e6291 commit 00366b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public void checkForFontAndColors() {
if (boldItalicFontFile.exists() && boldItalicFontFile.length() > 0) {
newBoldItalicTypeface = Typeface.createFromFile(boldItalicFontFile);
} else {
newBoldItalicTypeface = newItalicTypeface != newTypeface ? newItalicTypeface : newBoldTypeface;
newBoldItalicTypeface = newBoldTypeface != newTypeface ? newBoldTypeface : newItalicTypeface;
}

mActivity.getTerminalView().setTypefaces(newTypeface, newItalicTypeface, newBoldTypeface, newBoldItalicTypeface);
Expand Down
29 changes: 27 additions & 2 deletions terminal-view/src/main/java/com/termux/view/TerminalRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.util.Log;

import com.termux.terminal.TerminalBuffer;
import com.termux.terminal.TerminalEmulator;
Expand All @@ -17,6 +18,9 @@
* Saves font metrics, so needs to be recreated each time the typeface or font size changes.
*/
public final class TerminalRenderer {
boolean uniqueItalicTypeface;
boolean uniqueBoldTypeface;
boolean uniqueBoldItalicTypeface;

final int mTextSize;
final Typeface mTypeface;
Expand All @@ -42,6 +46,11 @@ public TerminalRenderer(int textSize, Typeface typeface, Typeface italicTypeface
mBoldTypeface = boldTypeface;
mBoldItalicTypeface = boldItalicTypeface;

uniqueItalicTypeface = !mItalicTypeface.equals(mTypeface);
uniqueBoldTypeface = !mBoldTypeface.equals(mTypeface);
uniqueBoldItalicTypeface = !mBoldItalicTypeface.equals(mTypeface) && !mBoldItalicTypeface.equals(mItalicTypeface) && !mBoldItalicTypeface.equals(mBoldTypeface);


mTextPaint.setTypeface(typeface);
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(textSize);
Expand Down Expand Up @@ -177,10 +186,28 @@ private void drawTextRun(Canvas canvas, char[] text, int[] palette, float y, int

if (italic && bold) {
mTextPaint.setTypeface(mBoldItalicTypeface);
if (mBoldItalicTypeface.equals(mBoldTypeface) && uniqueBoldTypeface) {
mTextPaint.setFakeBoldText(false);
mTextPaint.setTextSkewX(-0.35f);
} else if (mBoldItalicTypeface.equals(mItalicTypeface) && uniqueItalicTypeface){
mTextPaint.setFakeBoldText(true);
mTextPaint.setTextSkewX(uniqueItalicTypeface ? 0.f : -0.35f);
} else {
mTextPaint.setFakeBoldText(false);
mTextPaint.setTextSkewX(0.f);
}
} else if (italic) {
mTextPaint.setTypeface(mItalicTypeface);
mTextPaint.setFakeBoldText(false);
mTextPaint.setTextSkewX(uniqueItalicTypeface ? 0.f : -0.35f);
} else if (bold) {
mTextPaint.setTypeface(mBoldTypeface);
mTextPaint.setFakeBoldText(!uniqueBoldTypeface);
mTextPaint.setTextSkewX(0.f);
} else {
mTextPaint.setTypeface(mTypeface);
mTextPaint.setFakeBoldText(false);
mTextPaint.setTextSkewX(0.f);
}

final float fontWidth = mTextPaint.measureText("X");
Expand Down Expand Up @@ -245,9 +272,7 @@ private void drawTextRun(Canvas canvas, char[] text, int[] palette, float y, int
foreColor = 0xFF000000 + (red << 16) + (green << 8) + blue;
}

mTextPaint.setFakeBoldText(bold && !mTextPaint.getTypeface().isBold());
mTextPaint.setUnderlineText(underline);
mTextPaint.setTextSkewX(italic && !mTextPaint.getTypeface().isItalic() ? -0.35f : 0.f);
mTextPaint.setStrikeThruText(strikeThrough);
mTextPaint.setColor(foreColor);

Expand Down

0 comments on commit 00366b4

Please sign in to comment.