Skip to content

Commit

Permalink
Add support for "Monospace" control code (ASCII 0x11). By now just ig…
Browse files Browse the repository at this point in the history
…nore it. (#2672)
  • Loading branch information
ctrlaltca committed Aug 2, 2024
1 parent 13a6fc3 commit cf5a03a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/kvilib/irc/KviControlCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace KviControlCodes
case KviControlCodes::Underline:
case KviControlCodes::Bold:
case KviControlCodes::Italic:
case KviControlCodes::Monospace:
case KviControlCodes::Reset:
case KviControlCodes::Reverse:
case KviControlCodes::CryptEscape:
Expand Down
5 changes: 3 additions & 2 deletions src/kvilib/irc/KviControlCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
// 008 BS Backspace (Should not be assigned: terminal control)
// 009 HT Horizontal tabulation (Should not be assigned: terminal control)
// 010 LF Line feed (Should not be assigned: terminal control)
// 011 VT Vertical tabulation (Should not be assigned: terminal control)
// 011 VT Vertical tabulation ( Monospace text )
// 012 FF Form feed (Should not be assigned: terminal control)
// 013 CR Carriage return (Should not be assigned: terminal control)
// 014 SO Shift out (Should not be assigned: terminal control)
// 015 SI Shift in ( Resets Bold,Color,Underline and Reverse ) (Conflicting with terminal control)
// 015 SI Shift in ( Resets Bold,Color,Underline,Monospace and Reverse ) (Conflicting with terminal control)
// 016 DLE Data link escape (Decent, can be assigned)
// 017 DC1 Device control 1 (Good to be assigned)
// 018 DC2 Device control 2 (Good to be assigned)
Expand Down Expand Up @@ -157,6 +157,7 @@ namespace KviControlCodes
UnIcon = 0x06, /**< Unicon, totally artificial and internal to KviIrcView */
ArbitraryBreak = UnIcon, /**< Arbitrary block break, totally artificial and internal to KviIrcView */
Reset = 0x0f, /**< Reset */
Monospace = 0x11, /**< Monospace */
Reverse = 0x16, /**< Reverse */
Icon = 0x1c, /**< Icon, KVIrc control code */
Italic = 0x1d, /**< Italic */
Expand Down
22 changes: 21 additions & 1 deletion src/kvirc/kernel/KviHtmlGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace KviHtmlGenerator
bool bCurBold = false;
bool bCurItalic = false;
bool bCurUnderline = false;
bool bCurMonospace = false;
bool bIgnoreIcons = false;
bool bShowIcons = KVI_OPTION_BOOL(KviOption_boolDrawEmoticons);
unsigned char uCurFore = Foreground;
Expand All @@ -51,7 +52,7 @@ namespace KviHtmlGenerator
unsigned int uStart = uIdx;

while(
(c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Icon) && ((c != ':') || bIgnoreIcons) && ((c != ';') || bIgnoreIcons) && ((c != '=') || bIgnoreIcons))
(c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Icon) && (c != KviControlCodes::Monospace) && ((c != ':') || bIgnoreIcons) && ((c != ';') || bIgnoreIcons) && ((c != '=') || bIgnoreIcons))
{
bIgnoreIcons = false;
if(c == '&')
Expand Down Expand Up @@ -158,6 +159,19 @@ namespace KviHtmlGenerator
}
}

if(bCurMonospace)
{
if(!bOpened)
{
szResult.append("<span style=\"font-family:monospace");
bOpened = true;
}
else
{
szResult.append(";font-family:monospace");
}
}

if(bOpened)
szResult.append(";\">");

Expand Down Expand Up @@ -193,6 +207,12 @@ namespace KviHtmlGenerator
++uIdx;
break;
}
case KviControlCodes::Monospace:
{
bCurMonospace = !bCurMonospace;
++uIdx;
break;
}
case KviControlCodes::Reset:
{
uCurFore = Foreground;
Expand Down
14 changes: 12 additions & 2 deletions src/kvirc/ui/KviInputEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class KviInputEditorTextBlock
IsItalic = 4,
IsUnderline = 8,
IsSpellingMistake = 16,
IsSelected = 32
IsSelected = 32,
IsMonospace = 64
};

public:
Expand Down Expand Up @@ -536,7 +537,7 @@ void KviInputEditor::rebuildTextBlocks()

#define NOT_CONTROL_CHAR() \
( \
(c > 32) || ((c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::CryptEscape) && (c != KviControlCodes::Icon)))
(c > 32) || ((c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Monospace) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::CryptEscape) && (c != KviControlCodes::Icon)))

// FIXME: get rid of getLastFontMetrics() ?
QFontMetrics * fm = getLastFontMetrics(font());
Expand Down Expand Up @@ -605,6 +606,12 @@ void KviInputEditor::rebuildTextBlocks()
else
uFlags |= KviInputEditorTextBlock::IsUnderline;
break;
case KviControlCodes::Monospace:
if(uFlags & KviInputEditorTextBlock::IsMonospace)
uFlags &= ~KviInputEditorTextBlock::IsMonospace;
else
uFlags |= KviInputEditorTextBlock::IsMonospace;
break;
case KviControlCodes::Reset:
uCurFore = KVI_INPUT_DEF_FORE;
uCurBack = KVI_INPUT_DEF_BACK;
Expand Down Expand Up @@ -976,6 +983,9 @@ QChar KviInputEditor::getSubstituteChar(unsigned short uControlCode)
case KviControlCodes::Italic:
return QChar('I');
break;
case KviControlCodes::Monospace:
return QChar('M');
break;
case KviControlCodes::Reset:
return QChar('O');
break;
Expand Down
6 changes: 6 additions & 0 deletions src/kvirc/ui/KviIrcView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@ void KviIrcView::paintEvent(QPaintEvent * p)
bool curBold = false;
bool curItalic = false;
bool curUnderline = false;
bool curMonospace = false;
char foreBeforeEscape = KviControlCodes::Black;
bool curLink = false;
bool bacWasTransp = false;
Expand Down Expand Up @@ -1256,10 +1257,14 @@ void KviIrcView::paintEvent(QPaintEvent * p)
case KviControlCodes::Underline:
curUnderline = !curUnderline;
break;
case KviControlCodes::Monospace:
curMonospace = !curMonospace;
break;
case KviControlCodes::Reset:
curBold = false;
curItalic = false;
curUnderline = false;
curMonospace = false;
bacWasTransp = false;
curFore = defaultFore;
curBack = defaultBack;
Expand Down Expand Up @@ -3004,6 +3009,7 @@ KviIrcViewWrappedBlock * KviIrcView::getLinkUnderMouse(int xPos, int yPos, QRect
case KviControlCodes::Bold:
case KviControlCodes::Italic:
case KviControlCodes::Underline:
case KviControlCodes::Monospace:
case KviControlCodes::Reverse:
case KviControlCodes::Reset:
szLink.append(QChar(l->pBlocks[iEndOfLInk].pChunk->type));
Expand Down
1 change: 1 addition & 0 deletions src/kvirc/ui/KviIrcView_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ void KviIrcView::addControlCharacter(KviIrcViewLineChunk * pC, QString & szSelec
case KviControlCodes::Bold:
case KviControlCodes::Italic:
case KviControlCodes::Underline:
case KviControlCodes::Monospace:
case KviControlCodes::Reverse:
case KviControlCodes::Reset:
szSelectionText.append(QChar(pC->type));
Expand Down
3 changes: 2 additions & 1 deletion src/kvirc/ui/KviIrcView_getTextLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ const kvi_wchar_t * KviIrcView::getTextLine(
nullptr ,nullptr ,nullptr ,nullptr ,
nullptr ,&&found_tab ,&&found_end_of_line ,nullptr ,
nullptr ,&&found_command_escape ,nullptr ,&&found_mirc_escape ,
nullptr ,nullptr ,nullptr ,nullptr ,
nullptr ,&&found_mirc_escape ,nullptr ,nullptr ,
nullptr ,nullptr ,&&found_mirc_escape ,nullptr ,
nullptr ,nullptr ,nullptr ,nullptr ,
&&found_icon_escape ,&&found_mirc_escape ,nullptr ,&&found_mirc_escape , // 000-031
Expand Down Expand Up @@ -749,6 +749,7 @@ const kvi_wchar_t * KviIrcView::getTextLine(
case KviControlCodes::Bold:
case KviControlCodes::Italic:
case KviControlCodes::Underline:
case KviControlCodes::Monospace:
case KviControlCodes::Reverse:
case KviControlCodes::Reset:
#ifdef COMPILE_USE_DYNAMIC_LABELS
Expand Down
9 changes: 9 additions & 0 deletions src/kvirc/ui/KviTopicWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ static bool isKviControlCode(unsigned short c)
case KviControlCodes::Bold:
case KviControlCodes::Italic:
case KviControlCodes::Underline:
case KviControlCodes::Monospace:
case KviControlCodes::Reverse:
case KviControlCodes::Reset:
case KviControlCodes::Icon:
Expand All @@ -249,6 +250,7 @@ void KviTopicWidget::paintColoredText(QPainter * p, QString text, const QPalette
bool curBold = false;
bool curItalic = false;
bool curUnderline = false;
bool curMonospace = false;
unsigned char curFore = KVI_LABEL_DEF_FORE; //default fore
unsigned char curBack = KVI_LABEL_DEF_BACK; //default back
int baseline = rect.top() + rect.height() - fm.descent() - 1;
Expand Down Expand Up @@ -342,6 +344,10 @@ void KviTopicWidget::paintColoredText(QPainter * p, QString text, const QPalette
curUnderline = !curUnderline;
++idx;
break;
case KviControlCodes::Monospace:
curMonospace = !curMonospace;
++idx;
break;
case KviControlCodes::Reverse:
{
char auxBack = curBack;
Expand Down Expand Up @@ -744,6 +750,9 @@ QChar KviTopicWidget::getSubstituteChar(unsigned short control_code)
case KviControlCodes::Italic:
return QChar('I');
break;
case KviControlCodes::Monospace:
return QChar('M');
break;
case KviControlCodes::Reset:
return QChar('O');
break;
Expand Down

0 comments on commit cf5a03a

Please sign in to comment.