From 9832cff1bbe42274afc96fda63882734ead28032 Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Wed, 16 Sep 2009 13:32:21 +0200
Subject: [PATCH] Fix monospace font optimization on Mac OS X. Trouble on the
 mac is that monospace is not exactly monospace, there can be a fractional
 component.

Thanks to Andreas Kling <info@andreaskling.com> for spotting
this and providing a fix.
---
 src/plugins/bineditor/bineditor.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/plugins/bineditor/bineditor.cpp b/src/plugins/bineditor/bineditor.cpp
index a3a142ad5df..4ab07964a38 100644
--- a/src/plugins/bineditor/bineditor.cpp
+++ b/src/plugins/bineditor/bineditor.cpp
@@ -126,6 +126,15 @@ void BinEditor::init()
         ++hex;
     }
 
+    if (m_isMonospacedFont && fm.width("M M ") != m_charWidth * 4) {
+        // On Qt/Mac, monospace font widths may have a fractional component
+        // This breaks the assumption that width("MMM") == width('M') * 3
+
+        m_isMonospacedFont = false;
+        m_columnWidth = fm.width("MMM");
+        m_labelWidth = fm.width("MMMM:MMMM:MMMM:MMMM");
+    }
+
     horizontalScrollBar()->setRange(0, 2 * m_margin + 16 * m_columnWidth
                                     + m_labelWidth + m_textWidth - viewport()->width());
     horizontalScrollBar()->setPageStep(viewport()->width());
-- 
GitLab