#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE OEDEPICT DOCUMENTATION
###############################################################


def DrawHelloWorld(image, font):

    w = image.GetWidth()
    h = image.GetHeight()
    image.Clear(oechem.OEWhite)

    pen = oedepict.OEPen()
    image.DrawRectangle(oedepict.OE2DPoint(1.0, 1.0), oedepict.OE2DPoint(w - 1.0, h - 1.0), pen)

    image.DrawText(oedepict.OE2DPoint(w / 2.0, h / 2.0), "Hello World!", font)


def DrawHelloWorlds(font, basefilename):

    image = oedepict.OEImage(200, 60)
    DrawHelloWorld(image, font)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)


font = oedepict.OEFont()
DrawHelloWorlds(font, "OEFont_Default")

# @ <SNIPPET-OEFONT-SET-FAMILY>
font = oedepict.OEFont()
font.SetFamily(oedepict.OEFontFamily_Times)
# @ </SNIPPET-OEFONT-SET-FAMILY>
DrawHelloWorlds(font, "OEFont_SetFamily")

# @ <SNIPPET-OEFONT-SET-STYLE>
font = oedepict.OEFont()
font.SetStyle(oedepict.OEFontStyle_Bold | oedepict.OEFontStyle_Italic)
# @ </SNIPPET-OEFONT-SET-STYLE>
DrawHelloWorlds(font, "OEFont_SetStyle")

# @ <SNIPPET-OEFONT-SET-SIZE>
font = oedepict.OEFont()
font.SetSize(30)
# @ </SNIPPET-OEFONT-SET-SIZE>
DrawHelloWorlds(font, "OEFont_SetSize")

# @ <SNIPPET-OEFONT-SET-ALIGNMENT>
font = oedepict.OEFont()
font.SetAlignment(oedepict.OEAlignment_Right)
# @ </SNIPPET-OEFONT-SET-ALIGNMENT>
DrawHelloWorlds(font, "OEFont_SetAlignment")

# @ <SNIPPET-OEFONT-SET-COLOR>
font = oedepict.OEFont()
font.SetColor(oechem.OERed)
# @ </SNIPPET-OEFONT-SET-COLOR>
DrawHelloWorlds(font, "OEFont_SetColor")

# @ <SNIPPET-OEFONT-SET-ROTATION-ANGLE>
font = oedepict.OEFont()
font.SetRotationAngle(180.0)
# @ </SNIPPET-OEFONT-SET-ROTATION-ANGLE>
DrawHelloWorlds(font, "OEFont_SetRotationAngle")
