luceda ipkiss教程 53:在版图上加中文

2023-12-24 23:27:19

要在版图上加中文,如:
在这里插入图片描述
可以通过如下方法实现:
首先,可以在ppt中加入文本框,在文本框中输入想要加到版图上的中文内容,如,复旦大学,并将文本框存为windows位图。
其次,通过如下代码就可以得到中文对应的版图:

# Copyright (C) 2021 Luceda
from technologies import silicon_photonics
import ipkiss3.all as i3

PIL_loaded = False
try:
    from PIL import Image

    PIL_loaded = True
except:
    pass

try:
    import Image

    PIL_loaded = True
except:
    pass

if not PIL_loaded:
    raise AssertionError(" PIL should be installed")


class BitmapGrating(i3.PCell):
    image = i3.DefinitionProperty()
    pixel = i3.ChildCellProperty()

    class Layout(i3.LayoutView):
        pixel_pitch = i3.Size2Property(default=(2.0, 2.0))

        def _generate_instances(self, insts):
            im = self.image
            w = im.size[0]
            h = im.size[1]
            pixels = im.getdata()

            period_x = self.pixel_pitch[0]
            period_y = self.pixel_pitch[1]

            for y in range(h):
                pen_down = False
                for x in range(w):
                    p = pixels[x + y * w]
                    if not pen_down:
                        if p == 0:
                            pen_down = True
                            start_x = x
                    elif not p == 0:
                        pen_down = False
                        n_x = x - start_x
                        if n_x > 1:
                            insts += i3.ARef(reference=self.pixel, origin=(start_x * period_x, -y * period_y),
                                             period=(period_x, period_y), n_o_periods=(n_x, 1))
                        else:
                            insts += i3.SRef(reference=self.pixel, position=(start_x * period_x, -y * period_y))
                if pen_down:
                    n_x = x - start_x + 1
                    if n_x > 1:
                        insts += i3.ARef(reference=self.pixel, origin=(start_x * period_x, -y * period_y),
                                         period=(period_x, period_y), n_o_periods=(n_x, 1))
                    else:
                        insts += i3.SRef(reference=self.pixel, position=(start_x * period_x, -y * period_y))

            return insts


class BitmapGratingFromFile(BitmapGrating):
    image = i3.LockedProperty()
    filename = i3.StringProperty()

    def _default_image(self):
        return Image.open(self.filename).convert("1")


class SquareBitmapGrating(BitmapGrating):
    pixel = i3.ChildCellProperty(locked=True)

    def _default_pixel(self):
        from picazzo3.phc.generic.holes import RectHole
        return RectHole(name="{}_pixel".format(self.name))
        # return i3.Rectangle(layer=self.layer,box_size=self.pixel_size)

    class Layout(BitmapGrating.Layout):
        # pass
        pixel_size = i3.Size2Property(default=(1.0, 1.0))
        layer = i3.LayerProperty(default=i3.TECH.PPLAYER.WG.HOLE)

        def _default_pixel(self):
            lv = self.cell.pixel.get_default_view(i3.LayoutView)
            lv.set(radii=(0.5 * self.pixel_size[0], 0.5 * self.pixel_size[1]), process=self.layer.process,
                   purpose=self.layer.purpose)
            return lv


class SquareBitmapGratingFromFile(BitmapGratingFromFile, SquareBitmapGrating):
    """ Load a bitmap from file and convert it to a grating:
        SquareBitmapGratingFromFile(filename = "xxx", pixel_size = (x,y), pixel_pitch = (x,y))
        """
    pass


if __name__ == '__main__':
    logo = SquareBitmapGratingFromFile(name="fudan", filename="fudan.bmp")
    logo_layout = logo.Layout(pixel_size=(1.5, 1.5), pixel_pitch=(3., 3.))
    logo_layout.write_gdsii("fudan.gds")

文章来源:https://blog.csdn.net/qq_34316088/article/details/135188097
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。