pikchr.bmx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ' Copyright (c) 2023 Bruce A Henderson
  2. '
  3. ' This software is provided 'as-is', without any express or implied
  4. ' warranty. In no event will the authors be held liable for any damages
  5. ' arising from the use of this software.
  6. '
  7. ' Permission is granted to anyone to use this software for any purpose,
  8. ' including commercial applications, and to alter it and redistribute it
  9. ' freely, subject to the following restrictions:
  10. '
  11. ' 1. The origin of this software must not be misrepresented; you must not
  12. ' claim that you wrote the original software. If you use this software
  13. ' in a product, an acknowledgment in the product documentation would be
  14. ' appreciated but is not required.
  15. ' 2. Altered source versions must be plainly marked as such, and must not be
  16. ' misrepresented as being the original software.
  17. ' 3. This notice may not be removed or altered from any source distribution.
  18. '
  19. SuperStrict
  20. Rem
  21. bbdoc: A PIC-like markup language for diagrams in technical documentation.
  22. End Rem
  23. Module Text.Pikchr
  24. ModuleInfo "Version: 1.00"
  25. ModuleInfo "Author: Bruce A Henderson"
  26. ModuleInfo "License: zlib/libpng"
  27. ModuleInfo "pikchr - Copyright (C) 2020-09-01 by D. Richard Hipp <[email protected]>"
  28. ModuleInfo "Copyright: 2023 Bruce A Henderson"
  29. ModuleInfo "History: 1.00"
  30. ModuleInfo "History: Initial Release"
  31. Import "common.bmx"
  32. Rem
  33. bbdoc: Converts a #String of Pikchr markup, returning an SVG #String.
  34. End Rem
  35. Function PikChr:String(txt:String, class:String, flags:EPikChrFlags, width:Int Var, height:Int Var)
  36. Local t:Byte Ptr = txt.ToUTF8String()
  37. Local c:Byte Ptr
  38. If class Then
  39. c = class.ToUTF8String()
  40. End If
  41. Local w:Int, h:Int
  42. Local s:Byte Ptr = pikchr_(t, c, flags, VarPtr w, VarPtr h)
  43. width = w
  44. height = h
  45. MemFree(c)
  46. MemFree(t)
  47. Local res:String = String.FromUTF8String(s)
  48. free_(s)
  49. Return res
  50. End Function
  51. Private
  52. Extern
  53. Function pikchr_:Byte Ptr(zText:Byte Ptr, zClass:Byte Ptr, mFlags:EPikChrFlags, pnWidth:Int Ptr, pnHeight:Int Ptr)="pikchr"
  54. Function free_( buf:Byte Ptr )="void free( void * ) !"
  55. End Extern