Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
On TextFontChange, TextFontReference, TextEmphasis, TextIndent
Fix a miss use of TextIndent
  • Loading branch information
hilaire committed Sep 29, 2019
1 parent 49c19d8 commit 6cd24d4
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/NECompletion/NECMenuMorph.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ NECMenuMorph class >> convertToSHSymbol: aSymbol [

{ #category : #'help text' }
NECMenuMorph class >> explanationAttributes [
^{TextIndent spaceUsed; tabs: 2}
^{TextIndent tabs: 2}
]

{ #category : #'help text' }
Expand Down Expand Up @@ -229,7 +229,7 @@ NECMenuMorph class >> shortcut: aString text: secondString on: aTextStream [

{ #category : #'help text' }
NECMenuMorph class >> shortcutAttributes [
^ {TextIndent spaceUsed; tabs: 1. TextEmphasis italic }
^ {TextIndent tabs: 1. TextEmphasis italic }
]

{ #category : #'preferences-fonts' }
Expand Down
3 changes: 2 additions & 1 deletion src/Text-Core/TextFontChange.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"
A TextFontChange encodes a font change applicable over a given range of text. The font number is interpreted relative to the textStyle governing display of this text.
A TextFontChange encodes a font change applicable over a given range of text.
The font number is interpreted relative to the textStyle governing display of this text.
"
Class {
#name : #TextFontChange,
Expand Down
14 changes: 13 additions & 1 deletion src/Text-Core/TextFontReference.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
"
A TextFontReference encodes a font change applicable over a given range of text. The font reference is absolute: unlike a TextFontChange, it is independent of the textStyle governing display of this text.
A TextFontReference encodes a font change applicable over a given range of text.
The font reference is absolute: unlike a TextFontChange, it is independent of the textStyle governing display of this text.
-----exemple--------
| stream |
stream := TextStream on: (Text new: 100).
stream
nextPutAll: 'Small is ';
withAttribute: (TextFontReference toFont: (LogicalFont familyName: 'Source Sans Pro' pointSize: 8) )
do: [ stream nextPutAll: 'cool' ].
TextMorph new
newContents: stream contents;
openInWindow
"
Class {
#name : #TextFontReference,
Expand Down
13 changes: 12 additions & 1 deletion src/Text-Core/TextIndent.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
"
create a hanging indent.
An attribute to indent text at the left.
------exemple------
| stream |
stream := TextStream on: (Text new: 100).
stream
withAttribute: (TextIndent tabs: 1) do: [ stream nextPutAll: 'Pharo is cool'];
cr;
withAttribute: (TextIndent tabs: 2) do: [stream nextPutAll: 'Smalltalk is cool'].
TextMorph new
newContents: stream contents;
openInWindow.
"
Class {
#name : #TextIndent,
Expand Down
62 changes: 62 additions & 0 deletions src/Text-Tests/TextEmphasisTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ TextEmphasisTest >> testAdd [
self assert: (t1 = 2r11) description: 'bold and italics didn''t add correctly'
]

{ #category : #tests }
TextEmphasisTest >> testBold [
self assert: TextEmphasis bold equals: 1.

]

{ #category : #test }
TextEmphasisTest >> testDominatedByCmd0 [
self assert: TextEmphasis new dominatedByCmd0
]

{ #category : #tests }
TextEmphasisTest >> testDominates [
| text attr |
Expand Down Expand Up @@ -82,6 +93,24 @@ TextEmphasisTest >> testFromCode [
self assert: t1 value equals: 2r10101
]

{ #category : #tests }
TextEmphasisTest >> testItalic [
self assert: TextEmphasis italic equals: 2

]

{ #category : #tests }
TextEmphasisTest >> testNarrow [
self assert: TextEmphasis narrow equals: 8

]

{ #category : #tests }
TextEmphasisTest >> testNormal [
self assert: TextEmphasis normal equals: 0

]

{ #category : #tests }
TextEmphasisTest >> testRemove [
| t1 |
Expand All @@ -105,3 +134,36 @@ TextEmphasisTest >> testSet [
attr turnOff.
self deny: attr set].
]

{ #category : #tests }
TextEmphasisTest >> testStruckOut [
self assert: TextEmphasis struckOut equals: 16

]

{ #category : #tests }
TextEmphasisTest >> testUnderlined [
self assert: TextEmphasis underlined equals: 4

]

{ #category : #tests }
TextEmphasisTest >> testValue [
| attr |
"asking for the value return the emphasis code"
self assert: TextEmphasis normal value equals: 0.
self assert: TextEmphasis bold value equals: 1.
self assert: TextEmphasis italic value equals: 2.
self assert: TextEmphasis underlined value equals: 4.
self assert: TextEmphasis narrow value equals: 8.
self assert: TextEmphasis struckOut value equals: 16.

"We can add the emphasisCode, value should respond accordingly"
attr := TextEmphasis new emphasisCode:
TextEmphasis italic emphasisCode
+ TextEmphasis bold emphasisCode
+ TextEmphasis struckOut emphasisCode.
self assert: attr value equals: 2r10011.
"equality is based on the value"
self assert: attr equals: 2r10011
]
9 changes: 9 additions & 0 deletions src/Text-Tests/TextFontReferenceTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ TextFontReferenceTest >> setUp [
add: (TextFontReference
toFont: (StrikeFont familyName: 'NewYork' size: 15))
]

{ #category : #accessing }
TextFontReferenceTest >> testFont [
| font text |
font := LogicalFont familyName: 'Source Sans Pro' pointSize: 8.
text := 'Hello' asText addAttribute: (TextFontReference toFont: font).
"Querry the font in this text"
self assert: (text runs at: 1) first font equals: font
]
28 changes: 28 additions & 0 deletions src/Text-Tests/TextIndentTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Class {
#name : #TextIndentTest,
#superclass : #TestCase,
#category : #'Text-Tests-Base'
}

{ #category : #tests }
TextIndentTest >> testAmount [
| text |
text := 'Hello' asText addAttribute: (TextIndent amount: 2).
self assert: text runs first first amount equals: 2
]

{ #category : #tests }
TextIndentTest >> testDominates [
self assert: ((TextIndent tabs: 1) dominates: (TextIndent tabs: 2)).
self deny: ((TextIndent tabs: 1) dominates: TextEmphasis bold).
self deny: ((TextIndent tabs: 1) dominates: TextFontChange font2).

]

{ #category : #tests }
TextIndentTest >> testTabs [
| text |
"tabs: is a synonym for amount:"
text := 'Hello' asText addAttribute: (TextIndent tabs: 4).
self assert: text runs first first amount equals: 4
]
2 changes: 1 addition & 1 deletion src/Text-Tests/TextTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A TextTest is a test class for testing the behavior of Text
Class {
#name : #TextTest,
#superclass : #TestCase,
#category : #'Text-Tests'
#category : #'Text-Tests-Base'
}

{ #category : #tests }
Expand Down

0 comments on commit 6cd24d4

Please sign in to comment.