Skip to content

Commit

Permalink
Getting overline and strikethough working
Browse files Browse the repository at this point in the history
  • Loading branch information
ZILtoid1991 committed Aug 30, 2023
1 parent 332ebd8 commit d26b2d5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
14 changes: 9 additions & 5 deletions assets/test5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@
<font color="5">Color Nr.5</font>
</text>
<text id="example5">
<u>Underline</u>&spc;test.<br />
<u style="double">Underline</u> test.<br />
<u style="triple">Underline</u> test.<br />
<u lines="dotted">Underline</u> test.<br />
<u lines="stripes">Underline</u> test.<br />
<u>Underline</u>&#32;test.<br />
<!-- <u style="double">Underline</u>&#32;test.<br />
<u style="triple">Underline</u>&#32;test.<br /> -->
<u lines="dotted">Underline</u>&#32;test.<br />
<u lines="stripes">Underline</u>&#32;test.<br />
<s>Strikethrough</s>&#32;test.<br />
<o>Overstrike</o>&#32;test.<br />
<u perWord="yes">Per-word underline test.</u><br />
<u>This example shouldn't leave out whitespace characters.</u><br />
</text>
</etml>
50 changes: 32 additions & 18 deletions pixelperfectengine/src/pixelperfectengine/graphics/draw.d
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public class BitmapDrawer{
pdest += output.width;
}
}
///Inserts a midsection of the bitmap defined by slice (DEPRECATED)
/* ///Inserts a midsection of the bitmap defined by slice (DEPRECATED)
public deprecated void insertBitmapSlice(int x, int y, Bitmap8Bit bitmap, Coordinate slice) pure {
ubyte* psrc = bitmap.getPtr, pdest = output.getPtr;
pdest += x + output.width * y;
Expand All @@ -202,8 +202,8 @@ public class BitmapDrawer{
psrc += bmpWidth;
pdest += output.width;
}
}
///Inserts a midsection of the bitmap defined by slice as a color letter (DEPRECATED)
} */
/* ///Inserts a midsection of the bitmap defined by slice as a color letter (DEPRECATED)
public deprecated void insertColorLetter(int x, int y, Bitmap8Bit bitmap, ubyte color, Coordinate slice) pure {
if(slice.width - 1 <= 0) return;
if(slice.height - 1 <= 0) return;
Expand All @@ -217,9 +217,9 @@ public class BitmapDrawer{
psrc += bmpWidth;
pdest += output.width;
}
}
} */

///Draws colored text from monocromatic font.
/* ///Draws colored text from monocromatic font.
public void drawColorText(int x, int y, dstring text, Fontset!(Bitmap8Bit) fontset, ubyte color, uint style = 0) pure {
//color = 1;
const int length = fontset.getTextLength(text);
Expand All @@ -236,7 +236,7 @@ public class BitmapDrawer{
insertColorLetter(x + chinfo.xoffset, y + chinfo.yoffset, fontset.pages[chinfo.page], color, letterSlice);
x += chinfo.xadvance;
}
}
} */
/**
* Draws fully formatted text within a given prelimiter specified by pos.
* Offset specifies how much of the text is being obscured from the left hand side.
Expand Down Expand Up @@ -296,8 +296,8 @@ public class BitmapDrawer{
Bitmap8Bit workPad = new Bitmap8Bit(textWidth + 1, text.font.size * 2);
///Inserts a color letter.
void _insertColorLetter(Point pos, Bitmap8Bit bitmap, ubyte color, Box slice, int italics) pure nothrow {
if(slice.width - 1 <= 0) return;
if(slice.height - 1 <= 0) return;
if(slice.width <= 0) return;
if(slice.height <= 0) return;
ubyte* psrc = bitmap.getPtr, pdest = workPad.getPtr;
pdest += pos.x + workPad.width * pos.y;
const int bmpWidth = bitmap.width;
Expand All @@ -321,8 +321,7 @@ public class BitmapDrawer{
}
}
void _drawUnderlineSegment(uint style, int vOffset, int from, int to, ubyte color) pure {

switch ( style & FormattingFlags.ulLineStyle ) {
switch (style & FormattingFlags.ulLineStyle) {
case FormattingFlags.underlineDotted:
for (int x = from ; x <= to ; x++) {
workPad.writePixel(x, vOffset, dottedLine[x & 1] & color);
Expand All @@ -334,12 +333,25 @@ public class BitmapDrawer{
}
break;
default:
for (int i = (style & FormattingFlags.ulLineMultiplier) ; i >= 0 ; i--){
for (int x = from ; x <= to ; x++) {
workPad.writePixel(x, vOffset, color);
}
/* for (int i = (style & FormattingFlags.ulLineMultiplier) ; i >= 0 ; i--){
if (vOffset + ((i>>7) * 2) > workPad.height) continue; */
for (int x = from ; x <= to ; x++) {
workPad.writePixel(x, vOffset/* + ((i>>7) * 2) */, color);
}
/* } */
break;
}
}
void _drawOtherLines(uint style, int vOffset, int from, int to, ubyte color) pure {
if (style & FormattingFlags.strikeThrough) {
for (int x = from ; x <= to ; x++) {
workPad.writePixel(x, vOffset / 2, color);
}
}
if (style & FormattingFlags.overline) {
for (int x = from ; x <= to ; x++) {
workPad.writePixel(x, 0, color);
}
}
}
//const int targetX = textWidth - offset > pos.width ? pos.right : pos.left + textWidth;
Expand Down Expand Up @@ -389,6 +401,8 @@ public class BitmapDrawer{
!((currTextChunk.formatting.formatFlags & FormattingFlags.underlinePerWord) && isWhiteSpaceMB(chr)))
_drawUnderlineSegment(currTextChunk.formatting.formatFlags, currTextChunk.formatting.font.size, pX,
pX + chrInfo.xadvance, currTextChunk.formatting.color);
_drawOtherLines(currTextChunk.formatting.formatFlags, currTextChunk.formatting.font.size, pX,
pX + chrInfo.xadvance, currTextChunk.formatting.color);
pX += chrInfo.xadvance + currTextChunk.formatting.getKerning(prevChar, chr);
currCharPos++;
prevChar = chr;
Expand Down Expand Up @@ -419,7 +433,7 @@ public class BitmapDrawer{
bitBLT(renderTarget, workPad, textSlice);
return status;
}
///Draws text to the given point. DEPRECATED!
/* ///Draws text to the given point. DEPRECATED!
deprecated public void drawText(int x, int y, dstring text, Fontset!(Bitmap8Bit) fontset, uint style = 0) pure {
const int length = fontset.getTextLength(text);
//writeln(text);
Expand All @@ -439,8 +453,8 @@ public class BitmapDrawer{
insertBitmapSlice(x + chinfo.xoffset, y + chinfo.yoffset, fontset.pages[chinfo.page], letterSlice);
x += chinfo.xadvance;
}
}
///Inserts a bitmap using blitter. DEPRECATED
} */
/* ///Inserts a bitmap using blitter. DEPRECATED
deprecated public void insertBitmap(int x, int y, Bitmap8Bit bitmap) pure {
ubyte* psrc = bitmap.getPtr, pdest = output.getPtr;
pdest += x + output.width * y;
Expand All @@ -450,7 +464,7 @@ public class BitmapDrawer{
psrc += length;
pdest += output.width;
}
}
} */
}
/**
* Font formatting flags.
Expand Down
18 changes: 11 additions & 7 deletions pixelperfectengine/src/pixelperfectengine/system/lang/textparser.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public import pixelperfectengine.graphics.text;
public import pixelperfectengine.system.exc;
//public import pixelperfectengine.system.etc : isInteger;

import newxml;

import newxml.interfaces : XMLException;
import std.utf : toUTF32, toUTF8;
import std.conv : to;
Expand Down Expand Up @@ -50,10 +50,10 @@ public class TextParserTempl(BitmapType = Bitmap8Bit)
public CharacterFormattingInfo!BitmapType defaultFormatting() @property @safe pure nothrow @nogc {
return defFrmt;
}
private final ChrFormat currFrmt() @property @safe pure nothrow @nogc {
private ChrFormat currFrmt() @property @safe pure nothrow @nogc {
return frmtStack[$ - 1];
}
private final ref ChrFormat defFrmt() @property @safe pure nothrow @nogc {
private ref ChrFormat defFrmt() @property @safe pure nothrow @nogc {
return chrFrmt[0];
}
///Sets/gets the input
Expand All @@ -64,7 +64,11 @@ public class TextParserTempl(BitmapType = Bitmap8Bit)
* Parses the formatted text, then sets the output values.
*/
public void parse() {
auto parser0 = _input.lexer.parser.cursor.saxParser;
auto createParser() {
import newxml;
return _input.lexer.parser.cursor.saxParser;
}
auto parser0 = createParser;
parser0.setSource(_input);
//add whitespace entities
//parser0.cursor.parser.chrEntities["spc"] = " ";
Expand Down Expand Up @@ -196,10 +200,10 @@ public class TextParserTempl(BitmapType = Bitmap8Bit)
newFrmt.formatFlags |= FormattingFlags.underlineDouble;
break;
case "triple":
newFrmt.formatFlags |= FormattingFlags.underlineDouble;
newFrmt.formatFlags |= FormattingFlags.underlineTriple;
break;
case "quad":
newFrmt.formatFlags |= FormattingFlags.underlineDouble;
newFrmt.formatFlags |= FormattingFlags.underlineQuadruple;
break;
default:
break;
Expand All @@ -209,7 +213,7 @@ public class TextParserTempl(BitmapType = Bitmap8Bit)
newFrmt.formatFlags &= ~FormattingFlags.ulLineStyle;
switch (lines) {
case "dotted":
newFrmt.formatFlags |= FormattingFlags.underlineDouble;
newFrmt.formatFlags |= FormattingFlags.underlineDotted;
break;
case "wavy":
newFrmt.formatFlags |= FormattingFlags.underlineWavy;
Expand Down

0 comments on commit d26b2d5

Please sign in to comment.