ExDrawFonts.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("../DrawExamples.js");
  20. /**
  21. * \class ExDrawFonts
  22. * \ingroup ecma_misc_examples_draw
  23. * Adds a text entity for every CAD font available on the system.
  24. */
  25. function ExDrawFonts(guiAction) {
  26. DrawExamples.call(this, guiAction);
  27. }
  28. ExDrawFonts.prototype = new DrawExamples();
  29. ExDrawFonts.prototype.beginEvent = function() {
  30. DrawExamples.prototype.beginEvent.call(this);
  31. var x = 0;
  32. var y = 10;
  33. // create an operation for adding objects:
  34. var op = new RAddObjectsOperation();
  35. var fontNames = RFontList.getNames();
  36. for (var i=0; i<fontNames.length; i++) {
  37. var fontName = fontNames[i];
  38. if (y<0) {
  39. y = 10;
  40. x += 30;
  41. }
  42. // create a text entity and add it to the operation:
  43. var text = new RTextEntity(
  44. this.getDocument(),
  45. new RTextData(
  46. new RVector(x,y), // position
  47. new RVector(x,y), // alignment point
  48. 1.0, // height
  49. 0.0, // text width (ignored for now)
  50. RS.VAlignTop, // alignments
  51. RS.HAlignCenter,
  52. RS.LeftToRight,
  53. RS.Exact,
  54. 1.0, // line spacing factor
  55. "Abcdefg (" + fontName + ")", // the text
  56. fontName, // font
  57. false, // bold
  58. false, // italic
  59. 0.0, // angle
  60. false // simple text without formatting
  61. )
  62. );
  63. op.addObject(text);
  64. y-=2;
  65. }
  66. // apply the operation to the current drawing:
  67. this.getDocumentInterface().applyOperation(op);
  68. this.terminate();
  69. };
  70. ExDrawFonts.init = function(basePath) {
  71. var action = new RGuiAction(qsTr("Draw &Fonts"), RMainWindowQt.getMainWindow());
  72. action.setRequiresDocument(true);
  73. action.setScriptFile(basePath + "/ExDrawFonts.js");
  74. action.setGroupSortOrder(73100);
  75. action.setSortOrder(400);
  76. action.setWidgetNames(["DrawExamplesMenu"]);
  77. };