Skip to content

Commit

Permalink
centered name text
Browse files Browse the repository at this point in the history
  • Loading branch information
cracked-machine committed Feb 4, 2024
1 parent 4a7a917 commit 3d1334a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
8 changes: 4 additions & 4 deletions doc/example/report.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![memory map diagram](report.png)
|name|origin|size|remaining|collisions
|:-|:-|:-|:-|:-|
|<span style='color:gray'>kernel</span>|0x10|0x50|-0x10|{'rootfs': '0x50'}|
|<span style='color:darkviolet'>uboot</span>|0xD0|0x50|-0x10|{'uboot-scr': '0x110'}|
|<span style='color:skyblue'>rootfs</span>|0x50|0x30|0x10|{'kernel': '0x50'}|
|<span style='color:deepskyblue'>kernel</span>|0x10|0x50|-0x10|{'rootfs': '0x50'}|
|<span style='color:midnightblue'>uboot</span>|0xD0|0x50|-0x10|{'uboot-scr': '0x110'}|
|<span style='color:darkblue'>rootfs</span>|0x50|0x30|0x10|{'kernel': '0x50'}|
|<span style='color:dimgray'>dtb</span>|0x90|0x30|0x10|{}|
|<span style='color:slategray'>uboot-scr</span>|0x110|0x30|0x2a8|{'uboot': '0x110'}|
|<span style='color:mediumseagreen'>uboot-scr</span>|0x110|0x30|0x2a8|{'uboot': '0x110'}|
Binary file modified doc/example/report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 27 additions & 7 deletions mm/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MemoryMap:
"""height of the diagram image"""
width = 500
"""width of the diagram image"""
bgcolour = "oldlace"

def __init__(self):
self._legend_width = 50
Expand All @@ -50,7 +51,7 @@ def __init__(self):
def _create_diagram(self, region_list: List[mm.types.Region]):

# init the main image
img_main = PIL.Image.new("RGB", (MemoryMap.width, MemoryMap.height), color=(255, 255, 255))
img_main = PIL.Image.new("RGB", (MemoryMap.width, MemoryMap.height), color=MemoryMap.bgcolour)

# this is the x-axis drawing offset for each region
# we increment this each time we draw a region to clearly show overlaps
Expand All @@ -77,12 +78,31 @@ def _create_diagram(self, region_list: List[mm.types.Region]):
outline="black",
width=1,
)
name_text_font = PIL.ImageFont.load_default(10)
name_text_img = PIL.Image.new("RGB", (60, 15), color=(255, 255, 255))
name_text_canvas = PIL.ImageDraw.Draw(name_text_img)
name_text_canvas.text((0, 0), region.name, fill="black", font=name_text_font)
name_text_img = name_text_img.rotate(180)
region_img.paste(name_text_img, (10, 10))

# draw name text
ntext_img_width = 60
ntext_img_height = 7
ntext_font = PIL.ImageFont.load_default(ntext_img_height)
ntext_img = PIL.Image.new(
"RGB",
(ntext_img_width, ntext_img_height),
color=MemoryMap.bgcolour)

ntext_canvas = PIL.ImageDraw.Draw(ntext_img)

_, _, ntext_width, ntext_height = ntext_canvas.textbbox(
(0, 0),
region.name,
font=ntext_font)

ntext_canvas.text(
((ntext_img_width-ntext_width)/2,
(ntext_img_height-ntext_height)/2-1),
region.name, fill="black",
font=ntext_font)

ntext_img = ntext_img.rotate(180)
region_img.paste(ntext_img, (5, 5))


### Address Text
Expand Down

0 comments on commit 3d1334a

Please sign in to comment.