Code: Select all
Procedure PrintRecipe(recipeName.s, image.i, ingredients.s, method.s)
recipeTitleFont = LoadFont(#PB_Any, "Arial", 24, #PB_Font_Bold)
recipeBodyFonts = LoadFont(#PB_Any, "Times New Roman", 14)
recipeHeaderFonts = LoadFont(#PB_Any, "Times New Roman", 22,
#PB_Font_Bold | #PB_Font_Italic)
If PrintRequester()
If StartPrinting("Fangbeast's Recipe Printer")
If StartVectorDrawing(PrinterVectorOutput(#PB_Unit_Millimeter))
frameWidth = 1
singleSpace = 5
doubleSpace = 10
pageMargin = 10
pageWidth = VectorOutputWidth()
pageHeight = VectorOutputHeight()
imgAspect.d = ImageWidth(image) / ImageHeight(image)
imgWidth.d = (pageWidth - (pageMargin * 2)) / 2
imgHeight.d = imgWidth * imgAspect
MovePathCursor(pageMargin, pageMargin)
AddPathLine(pageWidth - (pageMargin * 2), 0, #PB_Path_Relative)
AddPathLine(0, pageHeight - (pageMargin * 2), #PB_Path_Relative)
AddPathLine(-(pageWidth - (pageMargin * 2)), 0, #PB_Path_Relative)
AddPathLine(0, -(pageHeight - (pageMargin * 2)), #PB_Path_Relative)
StrokePath(frameWidth, #PB_Path_SquareEnd)
VectorFont(FontID(recipeTitleFont))
VectorSourceColor(RGBA(0, 0, 155, 255))
titleXMargin = (pageWidth - VectorTextWidth(recipeName)) / 2
titleYMargin = pageMargin + singleSpace
MovePathCursor(titleXMargin, titleYMargin)
DrawVectorText(recipeName)
startX = pageMargin + singleSpace
startY = PathCursorY() + (singleSpace * 3)
MovePathCursor(startX, startY)
DrawVectorImage(ImageID(image), 255, imgWidth, imgHeight)
imageBase = PathCursorY()
startX = PathCursorX() + singleSpace
VectorFont(FontID(recipeHeaderFonts))
VectorSourceColor(RGBA(0, 0, 0, 255))
MovePathCursor(startX, startY)
DrawVectorText("Ingredients")
startY = PathCursorY() + doubleSpace
VectorFont(FontID(recipeBodyFonts))
MovePathCursor(startX, startY)
paragraphWidth = pageWidth - (startX + pageMargin + singleSpace)
DrawVectorParagraph(ingredients, paragraphWidth, 150)
startX = pageMargin + singleSpace
startY = imageBase + doubleSpace
VectorFont(FontID(recipeHeaderFonts))
VectorSourceColor(RGBA(0, 0, 0, 255))
MovePathCursor(startX, startY)
DrawVectorText("Method")
startY = PathCursorY() + doubleSpace
VectorFont(FontID(recipeBodyFonts))
MovePathCursor(startX, startY)
paragraphWidth = pageWidth - ((pageMargin * 2) + doubleSpace)
paragraphHeight = pageHeight - (startY + pageMargin)
DrawVectorParagraph(method, paragraphWidth, paragraphHeight)
StopVectorDrawing()
EndIf
EndIf
StopPrinting()
EndIf
EndProcedure
;demo for downloading sample recipe files from DropBox (requires PureBasic v5.4+)
UseJPEGImageDecoder()
InitNetwork()
Define.s ingredients, method, recipeName = "Mini Strawberry Cheesecakes"
ReceiveHTTPFile("https://www.dropbox.com/s/sd0xaeqybtehb1x/cheeseCake.jpg?dl=1",
GetTemporaryDirectory() + "cheeseCake.jpg")
image = LoadImage(#PB_Any, GetTemporaryDirectory() + "cheeseCake.jpg")
ReceiveHTTPFile("https://www.dropbox.com/s/m2hnogqhab2b588/ingredients.txt?dl=1",
GetTemporaryDirectory() + "ingredients.txt")
ReadFile(0, GetTemporaryDirectory() + "ingredients.txt")
While Not Eof(0)
ingredients + ReadString(0) + #CRLF$
Wend
CloseFile(0)
ReceiveHTTPFile("https://www.dropbox.com/s/lh517igi6bddtgh/method.txt?dl=1",
GetTemporaryDirectory() + "method.txt")
ReadFile(0, GetTemporaryDirectory() + "method.txt")
While Not Eof(0)
method + ReadString(0) + #CRLF$
Wend
CloseFile(0)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Any, #PB_Any, 600, 300, "Recipe Printer", wFlags)
TextGadget(#PB_Any, 10, 10, 180, 20, "Raw ingredients text:", #PB_Text_Center)
TextGadget(#PB_Any, 200, 10, 180, 20, "Raw method text:", #PB_Text_Center)
TextGadget(#PB_Any, 400, 10, 180, 20, "Recipe image:", #PB_Text_Center)
SetGadgetText(EditorGadget(#PB_Any, 10, 30, 180, 180, #PB_Editor_WordWrap), ingredients)
SetGadgetText(EditorGadget(#PB_Any, 200, 30, 180, 180, #PB_Editor_WordWrap), method)
CopyImage(image, image2)
ResizeImage(image2, 180, 180)
ImageGadget(#PB_Any, 400, 30, 180, 180, ImageID(image2))
printButton = ButtonGadget(#PB_Any, 10, 250, 580, 40, "PRINT SAMPLE RECIPE")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case printButton
PrintRecipe(recipeName, image, ingredients, method)
EndSelect
EndSelect
Until appQuit = 1
procedure, passing it the recipe name, ingredients and method texts, and an image. The rest of it is simply for the demonstration, downloading the sample files, display the raw data, etc.
Not perfect, but hope you'd find it useful.