OSDN Git Service

decoration, bold, margin left, uri
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Sat, 8 Dec 2007 15:41:19 +0000 (00:41 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Sat, 8 Dec 2007 15:41:19 +0000 (00:41 +0900)
src/FukuiNoNamari/thread_window.py

index 7688e4e..0315da6 100644 (file)
@@ -92,7 +92,7 @@ class WinWrap(winwrapbase.WinWrapBase):
         width = self.drawingarea.allocation.width
         sum_height = 0
         for layout in self.pangolayout:
-            layout.set_width(width * pango.SCALE)
+            layout.set_width((width - layout.marginleft) * pango.SCALE)
             layout.posY = sum_height
             x, y = layout.get_pixel_size()
             sum_height += y
@@ -115,7 +115,7 @@ class WinWrap(winwrapbase.WinWrapBase):
             area_bottom = view_y + self.drawingarea.allocation.height
             if layout_top <= area_bottom and layout_bottom >= area_top:
                 self.drawingarea.window.draw_layout(
-                    gc, 0, layout.posY - int(view_y), layout)
+                    gc, layout.marginleft, layout.posY - int(view_y), layout)
 
     def on_drawingarea_expose_event(self, widget, event, data=None):
         self.draw_viewport()
@@ -508,12 +508,46 @@ class WinWrap(winwrapbase.WinWrapBase):
 
     def process_queue(self, queue, num):
         text = ""
+        current_margin = False
+        attrlist = pango.AttrList()
         for data, bold, href, margin in queue:
+            data = data.encode("utf8")
+            if current_margin != margin:
+                layout = self.drawingarea.create_pango_layout(text)
+                layout.set_wrap(pango.WRAP_CHAR)
+                layout.posY = 0
+                layout.resnum = num
+                layout.set_attributes(attrlist)
+                if current_margin:
+                    layout.marginleft = 20
+                else:
+                    layout.marginleft = 0
+
+                self.pangolayout.append(layout)
+
+                current_margin = margin
+                text = ""
+                attrlist = pango.AttrList()
+
+            if bold:
+                attrlist.insert(pango.AttrWeight(
+                    pango.WEIGHT_BOLD, len(text), len(text) + len(data)))
+            if href:
+                attrlist.insert(pango.AttrUnderline(
+                    pango.UNDERLINE_SINGLE, len(text), len(text) + len(data)))
+
             text += data
-        layout = self.drawingarea.create_pango_layout(text)
-        layout.set_wrap(pango.WRAP_CHAR)
-        layout.posY = 0
-        layout.resnum = num
+
+        if text != "":
+            layout = self.drawingarea.create_pango_layout(text)
+            layout.set_wrap(pango.WRAP_CHAR)
+            layout.posY = 0
+            layout.resnum = num
+            layout.set_attributes(attrlist)
+            if current_margin:
+                layout.marginleft = 20
+            else:
+                layout.marginleft = 0
         self.pangolayout.append(layout)
         self.relayout()
         self.drawingarea.queue_draw()