commit 1ec3ac3e888a44de5e5a113213dede7d3856f112
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 12 09:19:16 2022 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 12 09:19:16 2022 -0700
Add tab stop width control code
---
source/printHelper.cpp | 7 ++++++-
test/printHelperTests.cpp | 15 +++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index dc13994..04da465 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -81,6 +81,7 @@ int print(std::string str, int x, int y, uint8_t c) {
_ph_mem->drawState.text_y = y;
int homeX = x;
int homeY = y;
+ int tabStopWidth = 4;
uint8_t effectiveC = _ph_graphics->getDrawPalMappedColor(c);
@@ -178,6 +179,10 @@ int print(std::string str, int x, int y, uint8_t c) {
x = p0CharToNum(xChar) * 4;
y = p0CharToNum(yChar) * 4;
}
+ else if (commandChar == 's'){
+ uint8_t tswChar = str[++n];
+ tabStopWidth = p0CharToNum(tswChar);
+ }
}
else if (ch == 12) { //"\f{p0}" draw text with this foreground color
@@ -191,7 +196,7 @@ int print(std::string str, int x, int y, uint8_t c) {
y += 6;
}
else if (ch == '\t') {
- while (x % 16 > 0) {
+ while (x % (tabStopWidth*4) > 0) {
x++;
}
}
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index 872dd76..dfb4722 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -354,6 +354,21 @@ TEST_CASE("Print helper functions") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("p8scii special control code tab stop width(\\^s) ") {
+ graphics->cls();
+
+ print("\x06""sc \t:", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {49, 0, 0},
+ {49, 1, 6},
+ {49, 2, 0},
+ {49, 3, 6},
+ {49, 4, 0}
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
delete stubHost;