-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1970 from processing/dhowe-fix-to-bounds-detection
Fixes bug in bounds detection
- Loading branch information
Showing
4 changed files
with
154 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,152 @@ | ||
var _setup = function(p, font) { | ||
var txt, tb, tw, x = 20, y = 50; | ||
|
||
p.createCanvas(240, 160); | ||
p.textFont(font); | ||
p.textSize(20); | ||
|
||
p.stroke("blue"); | ||
p.line(x, 0, x, p.height); | ||
|
||
txt = " leading space"; | ||
tb = font.textBounds(txt, x, y); | ||
tw = p.textWidth(txt); | ||
p.stroke("black"); | ||
p.rect(tb.x, tb.y, tb.w, tb.h); | ||
p.noStroke(); | ||
p.text(txt, x, y); | ||
p.stroke("red"); | ||
p.line(x, y + 6, x + tw, y + 6); | ||
|
||
y = 80; | ||
txt = "traction waste"; | ||
tb = font.textBounds(txt, x, y); | ||
tw = p.textWidth(txt); | ||
p.stroke("black"); | ||
p.rect(tb.x, tb.y, tb.w, tb.h); | ||
p.noStroke(); | ||
p.text(txt, x, y); | ||
p.stroke("red"); | ||
p.line(x, y + 6, x + tw, y + 6); | ||
|
||
y = 110; | ||
txt = "trailing space "; | ||
tb = font.textBounds(txt, x, y); | ||
tw = p.textWidth(txt); | ||
p.stroke("black"); | ||
p.rect(tb.x, tb.y, tb.w, tb.h); | ||
p.noStroke(); | ||
p.text(txt, x, y); | ||
p.stroke("red"); | ||
p.line(x, y + 6, x + tw, y + 6); | ||
|
||
y = 140; | ||
txt = " "; | ||
tb = font.textBounds(txt, x, y); | ||
tw = p.textWidth(txt); | ||
p.stroke("black"); | ||
p.rect(tb.x, tb.y, tb.w, p.max(tb.h, 3)); | ||
p.noStroke(); | ||
p.text(txt, x, y); | ||
p.stroke("red"); | ||
p.line(x, y + 6, x + tw, y + 6); | ||
}; | ||
|
||
var textSketch = function(p) { | ||
p.setup = function() { | ||
p.loadFont("../acmesa.ttf", function(f) { | ||
_setup(p, f); | ||
}); | ||
}; | ||
}; | ||
|
||
var font, txt, tb; | ||
var textSketchMono = function(p) { | ||
p.setup = function() { | ||
p.loadFont("../AndaleMono.ttf", function(f) { | ||
_setup(p, f); | ||
}); | ||
}; | ||
}; | ||
|
||
var textSketch1958 = function(p) { // issue #1958 | ||
var font, lineW, words = "swimming back to the rock"; | ||
|
||
p.preload = function() { | ||
font = p.loadFont("../acmesa.ttf"); | ||
font = p.loadFont("../OpenSans-Regular.ttf"); | ||
}; | ||
|
||
p.setup = function() { | ||
function textAsWords(words, x, y) { | ||
var tw, spaceW = p.textWidth(" "); | ||
console.log(spaceW); | ||
for (var i = 0; i < words.length; i++) { | ||
if (i != 0) { | ||
tw = p.textWidth(words[i - 1]); | ||
x += tw + spaceW; | ||
p.stroke(0); | ||
p.noFill(); | ||
p.rect(x - spaceW, y + 5, spaceW, -25); | ||
} | ||
p.fill(0); | ||
p.noStroke(); | ||
p.text(words[i], x, y); | ||
} | ||
} | ||
|
||
p.createCanvas(240, 160); | ||
p.textFont(font); | ||
p.textSize(20); | ||
p.createCanvas(300, 200); | ||
p.background(255); | ||
|
||
txt = ' space first'; | ||
var tb = font.textBounds(txt,50,50,20); | ||
p.rect(tb.x,tb.y,tb.w,tb.h); | ||
p.text(txt, 50, 50); | ||
p.textSize(20); // Case 1: Default font | ||
p.noStroke(); | ||
p.text(words, 20, 50); | ||
textAsWords(words.split(" "), 20, 80); | ||
|
||
txt = 'trailing space?' | ||
tb = font.textBounds(txt,50,80,20); | ||
p.rect(tb.x,tb.y,tb.w,tb.h); | ||
p.text(txt, 50, 80); | ||
p.stroke(255, 0, 0); | ||
p.line(20, 0, 20, p.height); | ||
|
||
txt = 'trailing space? ' | ||
tb = font.textBounds(txt,50,110,20); | ||
p.rect(tb.x,tb.y,tb.w,tb.h); | ||
p.text(txt, 50, 110); | ||
lineW = p.textWidth(words); | ||
p.line(20 + lineW, 0, 20 + lineW, 90); | ||
|
||
var tw = font._textWidth(txt); | ||
tb = font.textBounds(' ',50,140,20); | ||
p.rect(tb.x,tb.y,tb.w,tb.h); | ||
}; | ||
p.textFont(font, 20); // Case 2: OpenSans | ||
p.noStroke(); | ||
p.text(words, 20, 120); | ||
textAsWords(words.split(" "), 20, 150); | ||
|
||
p.stroke(255, 0, 0); | ||
lineW = p.textWidth(words); | ||
p.line(20 + lineW, 100, 20 + lineW, p.height - 20); | ||
|
||
p.stroke(0); | ||
p.line(20, 160, 20 + p.textWidth(" "), 160); | ||
}; | ||
}; | ||
|
||
/*var textSketch1957 = function(p) { // issue #1957 | ||
var font; | ||
p.preload = function() { | ||
font = p.loadFont("../AndaleMono.ttf"); | ||
}; | ||
p.setup = function() { | ||
p.createCanvas(300, 400); | ||
p.textFont(font, 80); | ||
p.text("a", 0, 100); | ||
p.text("b", 0, 200); | ||
p.text("c", 0, 300); | ||
p.stroke(255,0,0); | ||
p.line(p.textWidth("a"), 0, p.textWidth("a"), p.height); | ||
p.line(p.textWidth("b"), 0, p.textWidth("b"), p.height); | ||
p.line(p.textWidth("c"), 0, p.textWidth("c"), p.height); | ||
p.noStroke(); | ||
p.textSize(10); | ||
p.text("a="+p.textWidth("a")+" b="+p.textWidth("b")+" c="+p.textWidth("c"), 10, 350); | ||
console.log(font); | ||
} | ||
} | ||
new p5(textSketch1957, "textSketch1957");*/ | ||
|
||
new p5(textSketch, 'textSketch'); | ||
new p5(textSketch, "textSketch"); | ||
new p5(textSketchMono, "textSketchMono"); | ||
new p5(textSketch1958, "textSketch1958"); |