ExText.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ExText
  22. * \ingroup ecma_misc_examples_draw
  23. * Adds a text entity to the drawing.
  24. */
  25. function ExText(guiAction) {
  26. DrawExamples.call(this, guiAction);
  27. }
  28. ExText.prototype = new DrawExamples();
  29. ExText.prototype.beginEvent = function() {
  30. DrawExamples.prototype.beginEvent.call(this);
  31. var pos = new RVector(5,10)
  32. // create an operation for adding objects:
  33. var op = new RAddObjectsOperation();
  34. // create a text entity and add it to the operation:
  35. var text = new RTextEntity(
  36. this.getDocument(),
  37. new RTextData(
  38. pos, // position
  39. pos, // alignment point
  40. 2.0, // height
  41. 0.0, // text width (ignored for now)
  42. RS.VAlignTop, // alignments
  43. RS.HAlignCenter,
  44. RS.LeftToRight,
  45. RS.Exact,
  46. 1.0, // line spacing factor
  47. "Test", // the text
  48. "Arial", // font
  49. false, // bold
  50. false, // italic
  51. 0.0, // angle
  52. false // simple text without formatting
  53. )
  54. );
  55. op.addObject(text);
  56. // apply the operation to the current drawing:
  57. this.getDocumentInterface().applyOperation(op);
  58. this.terminate();
  59. };
  60. ExText.init = function(basePath) {
  61. var action = new RGuiAction(qsTr("Text"), RMainWindowQt.getMainWindow());
  62. action.setRequiresDocument(true);
  63. action.setScriptFile(basePath + "/ExText.js");
  64. action.setStatusTip(qsTr("Draw text"));
  65. action.setGroupSortOrder(73100);
  66. action.setSortOrder(300);
  67. action.setWidgetNames(["DrawExamplesMenu"]);
  68. };