8 |
#include "scripteditor.h" |
#include "scripteditor.h" |
9 |
#include "global.h" |
#include "global.h" |
10 |
#include <gtk/gtkwidget.h> // for gtk_widget_modify_*() |
#include <gtk/gtkwidget.h> // for gtk_widget_modify_*() |
11 |
|
#if defined(__APPLE__) |
12 |
|
# include "MacHelper.h" |
13 |
|
#endif |
14 |
|
#include <math.h> // for log10() |
15 |
|
|
16 |
#if !USE_LS_SCRIPTVM |
#if !USE_LS_SCRIPTVM |
17 |
|
|
286 |
|
|
287 |
int ScriptEditor::currentFontSize() const { |
int ScriptEditor::currentFontSize() const { |
288 |
#if defined(__APPLE__) |
#if defined(__APPLE__) |
289 |
const int defaultFontSize = 13; |
const int defaultFontSize = 11; |
290 |
#else |
#else |
291 |
const int defaultFontSize = 10; |
const int defaultFontSize = 10; |
292 |
#endif |
#endif |
299 |
//printf("setFontSize(%d,%d)\n", size, save); |
//printf("setFontSize(%d,%d)\n", size, save); |
300 |
Pango::FontDescription fdesc; |
Pango::FontDescription fdesc; |
301 |
fdesc.set_family("monospace"); |
fdesc.set_family("monospace"); |
302 |
|
#if defined(__APPLE__) |
303 |
|
// fixes poor readability of default monospace font on Macs |
304 |
|
if (macIsMinMac10_6()) |
305 |
|
fdesc.set_family("Menlo"); |
306 |
|
#endif |
307 |
fdesc.set_size(size * PANGO_SCALE); |
fdesc.set_size(size * PANGO_SCALE); |
308 |
|
/*Glib::RefPtr<Pango::Context> context = m_textView.get_pango_context(); |
309 |
|
Cairo::FontOptions options; |
310 |
|
options.set_antialias(Cairo::ANTIALIAS_NONE); |
311 |
|
context->set_cairo_font_options(options);*/ |
312 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
313 |
m_lineNrView.modify_font(fdesc); |
m_lineNrView.modify_font(fdesc); |
314 |
m_textView.modify_font(fdesc); |
m_textView.modify_font(fdesc); |
338 |
const int n = m_textBuffer->get_line_count(); |
const int n = m_textBuffer->get_line_count(); |
339 |
const int old = m_lineNrBuffer->get_line_count(); |
const int old = m_lineNrBuffer->get_line_count(); |
340 |
if (n == old) return; |
if (n == old) return; |
341 |
|
const int digits = log10(n) + 1; |
342 |
|
const int bufSz = digits + 2; |
343 |
|
char* buf = new char[bufSz]; |
344 |
|
std::string sFmt1 = "%" + ToString(digits) + "d"; |
345 |
|
std::string sFmt2 = "\n%" + ToString(digits) + "d"; |
346 |
Glib::ustring s; |
Glib::ustring s; |
347 |
for (int i = 0; i < n; ++i) { |
for (int i = 0; i < n; ++i) { |
348 |
if (i) s += "\n"; |
snprintf(buf, bufSz, i ? sFmt2.c_str() : sFmt1.c_str(), i+1); |
349 |
s += ToString(i+1); |
s += buf; |
350 |
} |
} |
351 |
m_lineNrBuffer->remove_all_tags(m_lineNrBuffer->begin(), m_lineNrBuffer->end()); |
m_lineNrBuffer->remove_all_tags(m_lineNrBuffer->begin(), m_lineNrBuffer->end()); |
352 |
m_lineNrBuffer->set_text(s); |
m_lineNrBuffer->set_text(s); |
353 |
m_lineNrBuffer->apply_tag(m_lineNrTag, m_lineNrBuffer->begin(), m_lineNrBuffer->end()); |
m_lineNrBuffer->apply_tag(m_lineNrTag, m_lineNrBuffer->begin(), m_lineNrBuffer->end()); |
354 |
|
if (buf) delete[] buf; |
355 |
} |
} |
356 |
|
|
357 |
void ScriptEditor::onTextInserted(const Gtk::TextBuffer::iterator& itEnd, const Glib::ustring& txt, int length) { |
void ScriptEditor::onTextInserted(const Gtk::TextBuffer::iterator& itEnd, const Glib::ustring& txt, int length) { |