Changeset ded2b4e54b49492e039d814453f12549e56ad518
- Timestamp:
- 10/25/09 14:24:51 (4 years ago)
- Author:
- Benjamin Herr <ben@…>
- git-author:
- Benjamin Herr <ben@0x539.de> / 2009-01-16T17:38:22Z+0100
- Parents:
- 80d0eeda014ec64671fb9da68e646348a9165ded
- Children:
- 7cfad2e713662f0eeea22b5c5d19c6a9596c4413
- git-committer:
- Benjamin Herr <ben@0x539.de> / 2009-10-25T14:24:51Z+0100
- Message:
-
htmlexport: fixed bug with non-ascii chars, changed colour handling
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r44f4113
|
rded2b4e
|
|
| 222 | 222 | } |
| 223 | 223 | |
| | 224 | #include <iomanip> |
| | 225 | |
| 224 | 226 | #include <ctime> |
| | 227 | #include <cstring> |
| 225 | 228 | |
| 226 | 229 | #include <gtkmm/textbuffer.h> |
| … |
… |
|
| 265 | 268 | // split text by newlines so we can insert line number elements |
| 266 | 269 | gchar* text = gtk_text_iter_get_text(&begin, &next); |
| 267 | | try{ |
| 268 | | gchar* last_pos = text; |
| 269 | | for (gchar* i = text; *i; ++i) { |
| | 270 | try { |
| | 271 | gchar const* last_pos = text; |
| | 272 | for (gchar const* i = text; *i; ++i) { |
| 270 | 273 | if (*i != '\n') |
| 271 | 274 | continue; |
| … |
… |
|
| 273 | 276 | ++line_counter; |
| 274 | 277 | |
| 275 | | gchar* next_pos = i; |
| | 278 | gchar const* next_pos = i; |
| 276 | 279 | ++next_pos; |
| 277 | | last_node->add_child_text(Glib::ustring(last_pos, next_pos - last_pos)); |
| | 280 | last_node->add_child_text(Glib::ustring(last_pos, next_pos)); |
| 278 | 281 | last_pos = next_pos; |
| 279 | 282 | |
| … |
… |
|
| 351 | 354 | char session_info[] = "<placeholder for session info and path>"; |
| 352 | 355 | |
| 353 | | // TODO: do some more magic to make localising this easier |
| 354 | | node->add_child_text(_("Document generated by ")); |
| | 356 | // %1 is information about the document's location, session name, |
| | 357 | // %2 is current date as formatted by %c, |
| | 358 | // %3 is a link to the gobby site |
| | 359 | char const* translated = _("Document generated from %1 at %2 by %3"); |
| | 360 | char const* p = std::strstr(translated, "%3"); |
| | 361 | g_assert(p); |
| | 362 | node->add_child_text( |
| | 363 | Glib::ustring::compose(Glib::ustring(translated, p), session_info, time_str)); |
| | 364 | |
| 355 | 365 | xmlpp::Element* link = node->add_child("a"); |
| 356 | 366 | link->set_attribute("href", "http://gobby.0x539.de/"); |
| 357 | 367 | link->add_child_text(PACKAGE_STRING); |
| 358 | | node->add_child_text( |
| 359 | | Glib::ustring::compose(_(" %1 from %2 at %3"), |
| 360 | | PACKAGE_STRING, session_info, time_str)); |
| | 368 | |
| | 369 | if (*p != 0) |
| | 370 | node->add_child_text( |
| | 371 | Glib::ustring::compose(p+2 , session_info, time_str)); |
| 361 | 372 | } |
| 362 | 373 | |
| … |
… |
|
| 370 | 381 | guint id = inf_user_get_id(INF_USER(*i)); |
| 371 | 382 | gdouble hue = inf_text_user_get_hue(*i); |
| 372 | | gdouble r, g, b; |
| 373 | | // TODO: use Gdk::Color c; c.set_hsv(...) if we are not depending on 2.14 |
| 374 | | gtk_hsv_to_rgb(hue, 0.35, 1.0, &r, &g, &b); |
| 375 | | unsigned int rgb = |
| 376 | | ((static_cast<unsigned int>(r * 0xff) << 16) |
| 377 | | | (static_cast<unsigned int>(g * 0xff) << 8) |
| 378 | | | (static_cast<unsigned int>(b * 0xff))) & 0xffffff; |
| | 383 | if (hue == 1) |
| | 384 | hue = 0; |
| | 385 | |
| | 386 | Gdk::Color c; |
| | 387 | c.set_hsv(360.0 * hue, 0.35, 1.0); |
| 379 | 388 | gchar const* name = inf_user_get_name(INF_USER(*i)); |
| 380 | 389 | // TODO: figure out if we can get "written by <name>" tooltips easily |
| 381 | | std::ostringstream ss; |
| 382 | | ss |
| 383 | | << ".user_" << id << " {\n" |
| 384 | | << " background-color: #" << std::hex << rgb << ";\n" |
| 385 | | << "}\n"; |
| 386 | | |
| 387 | | css->add_child_text(ss.str()); |
| | 390 | unsigned int rgb = |
| | 391 | ((c.get_red() & 0xff00) << 8) |
| | 392 | | (c.get_green() & 0xff00) |
| | 393 | | ((c.get_blue() & 0xff00) >> 8); |
| | 394 | |
| | 395 | css->add_child_text(Glib::ustring::compose( |
| | 396 | ".user_%1 {\n" |
| | 397 | " background-color: #%2;\n" |
| | 398 | "}\n", |
| | 399 | id, |
| | 400 | Glib::ustring::format(std::hex, |
| | 401 | std::setw(6), |
| | 402 | std::setfill(L'0'), rgb))); |
| 388 | 403 | xmlpp::Element* item = list->add_child("li"); |
| 389 | 404 | item->set_attribute("class", Glib::ustring::compose("user_%1", id)); |
| … |
… |
|
| 426 | 441 | style->set_attribute("type", "text/css"); |
| 427 | 442 | add_user_colours(style, user_list, users); |
| | 443 | if (!user_list->cobj()->children) { |
| | 444 | body->remove_child(h2); |
| | 445 | body->remove_child(user_list); |
| | 446 | } |
| 428 | 447 | |
| 429 | 448 | style->add_child_text( |