mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-19 02:48:49 +00:00
Fix non-mono font token highlighting on graph (#825)
This commit is contained in:
parent
ff4bbb9aa0
commit
4dda930410
@ -52,6 +52,29 @@ public:
|
|||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int position(const QString &text, int offset)
|
||||||
|
{
|
||||||
|
int curWidth = 0;
|
||||||
|
QChar temp;
|
||||||
|
|
||||||
|
for (int i = 0; i < text.length(); i++) {
|
||||||
|
QChar ch = text[i];
|
||||||
|
|
||||||
|
if (ch.isHighSurrogate())
|
||||||
|
temp = ch;
|
||||||
|
else if (ch.isLowSurrogate())
|
||||||
|
curWidth += mFontMetrics.width(QString(temp) + ch);
|
||||||
|
else
|
||||||
|
curWidth += width(ch);
|
||||||
|
|
||||||
|
if (curWidth >= offset) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFontMetrics mFontMetrics;
|
QFontMetrics mFontMetrics;
|
||||||
uchar mWidths[0x10000 - 0xE000 + 0xD800];
|
uchar mWidths[0x10000 - 0xE000 + 0xD800];
|
||||||
|
@ -441,6 +441,7 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
// highlight selected tokens
|
// highlight selected tokens
|
||||||
if (highlight_token != nullptr) {
|
if (highlight_token != nullptr) {
|
||||||
int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight);
|
int y = block.y + (2 * charWidth) + (db.header_text.lines.size() * charHeight);
|
||||||
|
int tokenWidth = mFontMetrics->width(highlight_token->content);
|
||||||
|
|
||||||
for (Instr &instr : db.instrs) {
|
for (Instr &instr : db.instrs) {
|
||||||
int pos = -1;
|
int pos = -1;
|
||||||
@ -453,7 +454,8 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.fillRect(QRect(block.x + charWidth * 3 + pos * charWidth, y, highlight_token->length * charWidth,
|
int widthBefore = mFontMetrics->width(instr.plainText.left(pos));
|
||||||
|
p.fillRect(QRect(block.x + charWidth * 3 + widthBefore, y, tokenWidth,
|
||||||
charHeight), disassemblySelectionColor.lighter(250));
|
charHeight), disassemblySelectionColor.lighter(250));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -747,8 +749,12 @@ void DisassemblerGraphView::seekPrev()
|
|||||||
|
|
||||||
DisassemblerGraphView::Token *DisassemblerGraphView::getToken(Instr *instr, int x)
|
DisassemblerGraphView::Token *DisassemblerGraphView::getToken(Instr *instr, int x)
|
||||||
{
|
{
|
||||||
int clickedCharPos = x / charWidth - 3;
|
x -= (3 * charWidth); // Ignore left margin
|
||||||
|
if (x < 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int clickedCharPos = mFontMetrics->position(instr->plainText, x);
|
||||||
if (clickedCharPos > instr->plainText.length()) {
|
if (clickedCharPos > instr->plainText.length()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user