1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516from blockdiag.noderenderer import install_renderer17from blockdiag.noderenderer.base import NodeShape18from blockdiag.utils import XY192021class Note(NodeShape):22 def render_shape(self, drawer, _, **kwargs):23 fill = kwargs.get('fill')2425 m = self.metrics.cell(self.node)26 r = self.metrics.cellsize * 22728 tr = m.topright29 note = [m.topleft, XY(tr.x - r, tr.y), XY(tr.x, tr.y + r),30 m.bottomright, m.bottomleft, m.topleft]31 box = self.metrics.cell(self.node).box3233 # draw outline34 if kwargs.get('shadow'):35 note = self.shift_shadow(note)36 if kwargs.get('style') == 'blur':37 drawer.polygon(note, fill=fill, outline=fill,38 filter='transp-blur')39 else:40 drawer.polygon(note, fill=fill, outline=fill)41 elif self.node.background:42 drawer.polygon(note, fill=self.node.color,43 outline=self.node.color)44 drawer.image(box, self.node.background)45 drawer.polygon(note, fill="none",46 outline=self.node.linecolor, style=self.node.style)47 else:48 drawer.polygon(note, fill=self.node.color,49 outline=self.node.linecolor, style=self.node.style)5051 # draw folded52 if not kwargs.get('shadow'):53 folded = [XY(tr.x - r, tr.y),54 XY(tr.x - r, tr.y + r),55 XY(tr.x, tr.y + r)]56 drawer.line(folded, fill=self.node.linecolor,57 style=self.node.style)585960def setup(self):61 install_renderer('note', Note)