From d62d9c352c7628835695c0ee4d237cfac0982ab0 Mon Sep 17 00:00:00 2001 From: Jan Bliznicenko Date: Thu, 14 Oct 2021 15:23:09 +0200 Subject: [PATCH 1/2] Fixed multiline labels style --- .../OPRTStyledMultilineLabel.class.st | 79 ++++++++++++++----- 1 file changed, 58 insertions(+), 21 deletions(-) diff --git a/repository/OpenPonk-Roassal2/OPRTStyledMultilineLabel.class.st b/repository/OpenPonk-Roassal2/OPRTStyledMultilineLabel.class.st index d6d08240..5bbcdc03 100644 --- a/repository/OpenPonk-Roassal2/OPRTStyledMultilineLabel.class.st +++ b/repository/OpenPonk-Roassal2/OPRTStyledMultilineLabel.class.st @@ -20,30 +20,67 @@ OPRTStyledMultilineLabel >> trachelShapeFor: anElement [ ] { #category : #'trachel shape production' } -OPRTStyledMultilineLabel >> updateFor: anElement trachelShape: trachelShape [ - | lines lbl txt aColor fontSize | - aColor := self colorFor: anElement. - fontSize := self heightFor: anElement. +OPRTStyledMultilineLabel >> trachelShapeForMultiLine: anElement [ + + | colorForElement fontSizeForElement textForElement emphasisForElement fontNameForElement txt lines shape | + colorForElement := self colorFor: anElement. + fontSizeForElement := self heightFor: anElement. + textForElement := self textFor: anElement. + emphasisForElement := self emphasisFor: anElement. + fontNameForElement := self fontNameFor: anElement. + txt := self textFor: anElement. txt := txt copyReplaceAll: String tab with: ' '. lines := txt lines. - trachelShape numberOfShapes > lines size - ifTrue: [ trachelShape numberOfShapes - lines size - timesRepeat: [ trachelShape shapes last remove. - trachelShape removeLast ] ]. - lines size > trachelShape numberOfShapes - ifTrue: [ lines size - trachelShape numberOfShapes - timesRepeat: [ | shape | - shape := TRLabelShape new. - shape element: anElement. - trachelShape canvas addShape: shape. - trachelShape addShape: shape ]. - trachelShape positionShapesAfterBeingAdded ]. - lines - doWithIndex: [ :l :index | - lbl := (trachelShape shapes at: index) text: l. - lbl color: aColor. - lbl fontSize: fontSize ]. + + shape := TRCompositeShape new. + lines doWithIndex: [ :l :index | + | lbl | + lbl := TRStyledLabelShape new. + lbl + text: l; + color: colorForElement; + fontSize: fontSizeForElement; + emphasis: emphasisForElement; + fontName: fontNameForElement. + shape addShape: lbl ]. + shape verticalAndLeft. + + ^ shape +] + +{ #category : #'trachel shape production' } +OPRTStyledMultilineLabel >> updateFor: anElement trachelShape: trachelShape [ + + | lines colorForElement fontSizeForElement textForElement emphasisForElement fontNameForElement | + colorForElement := self colorFor: anElement. + fontSizeForElement := self heightFor: anElement. + textForElement := self textFor: anElement. + emphasisForElement := self emphasisFor: anElement. + fontNameForElement := self fontNameFor: anElement. + textForElement := textForElement + copyReplaceAll: String tab + with: ' '. + lines := textForElement lines. + trachelShape numberOfShapes > lines size ifTrue: [ + trachelShape numberOfShapes - lines size timesRepeat: [ + trachelShape shapes last remove. + trachelShape removeLast ] ]. + lines size > trachelShape numberOfShapes ifTrue: [ + lines size - trachelShape numberOfShapes timesRepeat: [ + | shape | + shape := TRLabelShape new. + shape element: anElement. + trachelShape canvas addShape: shape. + trachelShape addShape: shape ]. + trachelShape positionShapesAfterBeingAdded ]. + lines doWithIndex: [ :l :index | + (trachelShape shapes at: index) + text: l; + color: colorForElement; + fontSize: fontSizeForElement; + emphasis: emphasisForElement; + fontName: fontNameForElement ]. trachelShape verticalAndLeftWithoutReset. ^ trachelShape ] From c8de7700fa4e281395e726264e32f90a8d1bd275 Mon Sep 17 00:00:00 2001 From: Jan Bliznicenko Date: Thu, 14 Oct 2021 22:12:44 +0200 Subject: [PATCH 2/2] added export zoom setting --- .../OPRTCanvasExporter.class.st | 36 +++++++ .../OpenPonk-Spec/OPCanvasPresenter.class.st | 36 +++++-- .../OPExportCanvasDialog.class.st | 102 ++++++++++++++++++ .../OPExportDiagramWizard.class.st | 71 ------------ 4 files changed, 165 insertions(+), 80 deletions(-) create mode 100644 repository/OpenPonk-Roassal2/OPRTCanvasExporter.class.st create mode 100644 repository/OpenPonk-Spec/OPExportCanvasDialog.class.st delete mode 100644 repository/OpenPonk-Spec/OPExportDiagramWizard.class.st diff --git a/repository/OpenPonk-Roassal2/OPRTCanvasExporter.class.st b/repository/OpenPonk-Roassal2/OPRTCanvasExporter.class.st new file mode 100644 index 00000000..37bfc80c --- /dev/null +++ b/repository/OpenPonk-Roassal2/OPRTCanvasExporter.class.st @@ -0,0 +1,36 @@ +Class { + #name : #OPRTCanvasExporter, + #superclass : #RTCanvasExporter, + #category : #'OpenPonk-Roassal2' +} + +{ #category : #accessing } +OPRTCanvasExporter class >> maxWidthAndHeight [ + + ^ 10000 +] + +{ #category : #private } +OPRTCanvasExporter >> scaleToMorphLimits [ + + "scale down to estimated morph (maxWidthAndHeight) and exporter (maxArea) size limits" + + | scaledDown | + scaledDown := false. + self extent x > self class maxWidthAndHeight ifTrue: [ + scaledDown := true. + self scale: + self class maxWidthAndHeight / self extent x * self cameraScale ]. + self extent y > self class maxWidthAndHeight ifTrue: [ + scaledDown := true. + self scale: + self class maxWidthAndHeight / self extent y * self cameraScale ]. + scaledDown ifTrue: [ + GrowlMorph + openWithLabel: 'Warning' + contents: 'Image was forced to scale down to ' + , (self cameraScale * 100 printShowingDecimalPlaces: 0) + , ' % zoom due to technical restrictions (max resolution).' + backgroundColor: GrowlMorph theme warningBackgroundColor + labelColor: GrowlMorph theme textColor ] +] diff --git a/repository/OpenPonk-Spec/OPCanvasPresenter.class.st b/repository/OpenPonk-Spec/OPCanvasPresenter.class.st index 47a7a631..c65a4ef9 100644 --- a/repository/OpenPonk-Spec/OPCanvasPresenter.class.st +++ b/repository/OpenPonk-Spec/OPCanvasPresenter.class.st @@ -111,17 +111,28 @@ OPCanvasPresenter >> ensureKeyBindingsFor: aWidget [ { #category : #toolbar } OPCanvasPresenter >> exportAsPng [ - FDSaveFileDialog new - whenSelected: [ :file | self exportCanvasTo: file ]; - extensionFilters: {'Images' -> #(png)}; - defaultName: self editor diagramController model name asFileName , '.png'; + + OPExportCanvasDialog new + whenSelected: [ :file :zoom | self exportCanvasTo: file zoom: zoom ]; + extensionFilters: { ('Images' -> #( png )) }; + defaultName: + self editor diagramController model name asFileName , '.png'; open ] { #category : #toolbar } OPCanvasPresenter >> exportCanvasTo: aFile [ - | gridShape gridColor selectedElements | + self exportCanvasTo: aFile zoom: TRCamera new defaultCameraScale +] + +{ #category : #toolbar } +OPCanvasPresenter >> exportCanvasTo: aFileReference zoom: aNumber [ + + | gridShape gridColor selectedElements zoom | + zoom := aNumber = 1 + ifTrue: [ roassalView canvas camera defaultCameraScale ] + ifFalse: [ aNumber ]. gridShape := roassalView canvas shapes detect: [ :each | each isKindOf: TRCanvasGridShape ]. gridColor := gridShape color. @@ -129,14 +140,21 @@ OPCanvasPresenter >> exportCanvasTo: aFile [ self diagramController deselectAll. [ gridShape color: Color transparent. - (RTCanvasExporter canvas: roassalView canvas) + (OPRTCanvasExporter canvas: roassalView canvas) format: #png; whole; - defaultScale; + scale: zoom; oversizedBy: 20 @ 20; - fileName: aFile; + fileName: aFileReference; export. - self inform: 'Saved to ' , aFile pathString ] ensure: [ + UIManager default + inform: (String streamContents: [ :s | + s << 'Saved to ' << aFileReference pathString. + s + cr; + cr. + s << 'Click to open location' ]) + actionOnClick: [ aFileReference openInOSFileBrowser ] ] ensure: [ gridShape color: gridColor. selectedElements do: [ :each | "self diagramController selectFigure: " each announce: TRMouseLeftClick new ] ] diff --git a/repository/OpenPonk-Spec/OPExportCanvasDialog.class.st b/repository/OpenPonk-Spec/OPExportCanvasDialog.class.st new file mode 100644 index 00000000..2e9e2239 --- /dev/null +++ b/repository/OpenPonk-Spec/OPExportCanvasDialog.class.st @@ -0,0 +1,102 @@ +Class { + #name : #OPExportCanvasDialog, + #superclass : #FDSaveFileDialog, + #instVars : [ + 'zoomLabel', + 'zoomText', + 'zoomPercentageLabel' + ], + #category : #'OpenPonk-Spec' +} + +{ #category : #specs } +OPExportCanvasDialog class >> defaultSpec [ + + ^ SpecColumnLayout composed + newRow: [ :r | + r + newColumn: [ :c | c add: #bookmarksList ] width: 150; + newColumn: [ :c | + c add: #currentFolderLabel height: self toolbarHeight. + c add: #filesList ] ]; + newRow: [ :r | + r + add: #nameLabel width: 50; + add: #nameText; + add: #filtersDropList width: 200 ] + height: self toolbarHeight; + newRow: [ :r | + r + add: #zoomLabel width: 50; + add: #zoomText width: 40; + add: #zoomPercentageLabel. + r newColumn: [ :c | ]. + self dialogButtonsLayout: r ] + height: self toolbarHeight; + yourself +] + +{ #category : #actions } +OPExportCanvasDialog >> confirm [ + + | zoomNumber file | + file := self selectedEntry. + file ifNil: [ ^ self ]. + zoomNumber := (NumberParser + parse: zoomText text + onError: [ TRCamera new defaultCameraScale * 100 ]) + / 100. + zoomNumber < 0.01 ifTrue: [ + zoomNumber := TRCamera new defaultCameraScale ]. + onConfirmBlock cull: file cull: zoomNumber. + self delete +] + +{ #category : #initialization } +OPExportCanvasDialog >> initializePresenter [ + + super initializePresenter. + self initializeZoom +] + +{ #category : #initialization } +OPExportCanvasDialog >> initializeWidgets [ + + super initializeWidgets. + (zoomLabel := self newLabel) label: 'Zoom: '. + (zoomText := self newTextInput) autoAccept: true. + (zoomPercentageLabel := self newLabel) label: ' %'. + self focusOrder: { + nameText. + filtersDropList. + zoomText. + cancelButton. + confirmButton } +] + +{ #category : #initialization } +OPExportCanvasDialog >> initializeZoom [ + + zoomText + text: '100'; + whenTextIsAccepted: [ :text | + zoomText text: ((text select: #isDigit) takeFirst: 4) ] +] + +{ #category : #accessing } +OPExportCanvasDialog >> zoomLabel [ + + ^ zoomLabel +] + +{ #category : #accessing } +OPExportCanvasDialog >> zoomPercentageLabel [ + + ^ zoomPercentageLabel +] + +{ #category : #accessing } +OPExportCanvasDialog >> zoomText [ + + ^ zoomText +] diff --git a/repository/OpenPonk-Spec/OPExportDiagramWizard.class.st b/repository/OpenPonk-Spec/OPExportDiagramWizard.class.st deleted file mode 100644 index a47152d4..00000000 --- a/repository/OpenPonk-Spec/OPExportDiagramWizard.class.st +++ /dev/null @@ -1,71 +0,0 @@ -" -I am a wizard for exporting the diagram (Roassal canvas) to an image file. -" -Class { - #name : #OPExportDiagramWizard, - #superclass : #WizardControl, - #instVars : [ - 'modelName', - 'view' - ], - #category : #'OpenPonk-Spec-Wizards' -} - -{ #category : #adding } -OPExportDiagramWizard >> addExportPane [ - | pane | - pane := WizardSinglePane new. - pane name: 'Save diagram to a *.png file'. - pane - addPart: - (SaveChooseFilePart new - validExtensions: #(png); - yourself) - associatedTo: #targetFile. - "pane - addPart: - (TextFieldPart new - inGroupboxNamed: 'Heading'; - defaultValue: [ :args | modelName ]; - suffix: 'Added heading to the top left corner') - associatedTo: #diagramName." - self addPane: pane -] - -{ #category : #exporting } -OPExportDiagramWizard >> exportWith: aDictionary [ - - | gridShape gridColor | - (aDictionary at: #targetFile) ifNil: [ - ^ self inform: 'Export canceled.' ]. - gridShape := view canvas shapes detect: [ :each | - each isKindOf: TRCanvasGridShape ]. - gridColor := gridShape color. - [ - gridShape color: Color transparent. - (RTCanvasExporter canvas: view canvas) - format: #png; - whole; - defaultScale; - oversizedBy: 20 @ 20; - fileName: (aDictionary at: #targetFile); - export ] ensure: [ gridShape color: gridColor ] -] - -{ #category : #'initialize-release' } -OPExportDiagramWizard >> initialize [ - super initialize. - modelName := ''. - self addExportPane. - self atEndDo: [ :values | self exportWith: values ] -] - -{ #category : #accessing } -OPExportDiagramWizard >> modelName: aString [ - modelName := aString -] - -{ #category : #accessing } -OPExportDiagramWizard >> view: aView [ - view := aView -]