- fix bezier points
- set names on objects /me pets Humdinger git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28074 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
80fa95ad77
commit
456e89ccc2
@ -5,6 +5,7 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* François Revol <revol@free.fr>
|
* François Revol <revol@free.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StyledTextImporter.h"
|
#include "StyledTextImporter.h"
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
@ -38,7 +39,7 @@ using std::nothrow;
|
|||||||
|
|
||||||
class ShapeIterator : public BShapeIterator {
|
class ShapeIterator : public BShapeIterator {
|
||||||
public:
|
public:
|
||||||
ShapeIterator(Icon *icon, Shape *to, BPoint offset);
|
ShapeIterator(Icon *icon, Shape *to, BPoint offset, const char *name);
|
||||||
~ShapeIterator() {};
|
~ShapeIterator() {};
|
||||||
|
|
||||||
virtual status_t IterateMoveTo(BPoint *point);
|
virtual status_t IterateMoveTo(BPoint *point);
|
||||||
@ -54,15 +55,22 @@ class ShapeIterator : public BShapeIterator {
|
|||||||
Shape *fShape;
|
Shape *fShape;
|
||||||
VectorPath *fPath;
|
VectorPath *fPath;
|
||||||
BPoint fOffset;
|
BPoint fOffset;
|
||||||
|
const char *fName;
|
||||||
|
BPoint fLastPoint;
|
||||||
|
bool fHasLastPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
ShapeIterator::ShapeIterator(Icon *icon, Shape *to, BPoint offset)
|
ShapeIterator::ShapeIterator(Icon *icon, Shape *to, BPoint offset,
|
||||||
|
const char *name)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
fIcon = icon;
|
fIcon = icon;
|
||||||
fShape = to;
|
fShape = to;
|
||||||
fPath = NULL;
|
fPath = NULL;
|
||||||
fOffset = offset;
|
fOffset = offset;
|
||||||
|
fName = name;
|
||||||
|
fLastPoint = offset;
|
||||||
|
fHasLastPoint = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
@ -73,7 +81,9 @@ ShapeIterator::IterateMoveTo(BPoint *point)
|
|||||||
NextPath();
|
NextPath();
|
||||||
if (!CurrentPath())
|
if (!CurrentPath())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
fPath->AddPoint(fOffset + *point);
|
//fPath->AddPoint(fOffset + *point);
|
||||||
|
fLastPoint = fOffset + *point;
|
||||||
|
fHasLastPoint = true;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +93,12 @@ ShapeIterator::IterateLineTo(int32 lineCount, BPoint *linePts)
|
|||||||
CALLED();
|
CALLED();
|
||||||
if (!CurrentPath())
|
if (!CurrentPath())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
while (lineCount--)
|
while (lineCount--) {
|
||||||
fPath->AddPoint(fOffset + *linePts++);
|
fPath->AddPoint(fOffset + *linePts);
|
||||||
|
fLastPoint = fOffset + *linePts;
|
||||||
|
fHasLastPoint = true;
|
||||||
|
linePts++;
|
||||||
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,11 +108,17 @@ ShapeIterator::IterateBezierTo(int32 bezierCount, BPoint *bezierPts)
|
|||||||
CALLED();
|
CALLED();
|
||||||
if (!CurrentPath())
|
if (!CurrentPath())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
BPoint start(bezierPts[0]);
|
||||||
|
if (fHasLastPoint)
|
||||||
|
start = fLastPoint;
|
||||||
while (bezierCount--) {
|
while (bezierCount--) {
|
||||||
fPath->AddPoint(fOffset + bezierPts[1],
|
fPath->AddPoint(fOffset + bezierPts[0],
|
||||||
fOffset + bezierPts[0], fOffset + bezierPts[2], false);
|
fLastPoint, fOffset + bezierPts[1], true);
|
||||||
bezierPts += 3;
|
fLastPoint = fOffset + bezierPts[2];
|
||||||
|
bezierPts += 3;
|
||||||
}
|
}
|
||||||
|
fPath->AddPoint(fLastPoint);
|
||||||
|
fHasLastPoint = true;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +130,7 @@ ShapeIterator::IterateClose()
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
fPath->SetClosed(true);
|
fPath->SetClosed(true);
|
||||||
NextPath();
|
NextPath();
|
||||||
|
fHasLastPoint = false;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +141,7 @@ ShapeIterator::CurrentPath()
|
|||||||
if (fPath)
|
if (fPath)
|
||||||
return fPath;
|
return fPath;
|
||||||
fPath = new (nothrow) VectorPath();
|
fPath = new (nothrow) VectorPath();
|
||||||
|
fPath->SetName(fName);
|
||||||
return fPath;
|
return fPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +228,7 @@ StyledTextImporter::Import(Icon* icon, const entry_ref* ref)
|
|||||||
mio.SetSize((size_t)size + 1);
|
mio.SetSize((size_t)size + 1);
|
||||||
memset((void *)mio.Buffer(), 0, (size_t)size + 1);
|
memset((void *)mio.Buffer(), 0, (size_t)size + 1);
|
||||||
|
|
||||||
// TODO: read runs
|
// TODO: read runs from attribute
|
||||||
|
|
||||||
return _Import(icon, (const char *)mio.Buffer(), NULL);
|
return _Import(icon, (const char *)mio.Buffer(), NULL);
|
||||||
}
|
}
|
||||||
@ -257,7 +279,7 @@ StyledTextImporter::_Import(Icon* icon, const char *text, text_run_array *runs)
|
|||||||
while (run && currentRun < runs->count - 1 &&
|
while (run && currentRun < runs->count - 1 &&
|
||||||
i >= runs->runs[currentRun + 1].offset) {
|
i >= runs->runs[currentRun + 1].offset) {
|
||||||
run = &runs->runs[++currentRun];
|
run = &runs->runs[++currentRun];
|
||||||
printf("switching to run %d\n", currentRun);
|
//printf("switching to run %d\n", currentRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
int charLen;
|
int charLen;
|
||||||
@ -290,13 +312,17 @@ StyledTextImporter::_Import(Icon* icon, const char *text, text_run_array *runs)
|
|||||||
|
|
||||||
float charWidth;
|
float charWidth;
|
||||||
charWidth = font.StringWidth(str.String() + i, charLen);
|
charWidth = font.StringWidth(str.String() + i, charLen);
|
||||||
printf("StringWidth( %d) = %f\n", charLen, charWidth);
|
//printf("StringWidth( %d) = %f\n", charLen, charWidth);
|
||||||
|
BString glyphName(str.String() + i, charLen);
|
||||||
|
glyphName.Prepend("Glyph (");
|
||||||
|
glyphName.Append(")");
|
||||||
|
|
||||||
font.GetGlyphShapes((str.String() + i), 1, glyphs);
|
font.GetGlyphShapes((str.String() + i), 1, glyphs);
|
||||||
if (glyph.Bounds().IsValid()) {
|
if (glyph.Bounds().IsValid()) {
|
||||||
//offset.x += glyph.Bounds().Width();
|
//offset.x += glyph.Bounds().Width();
|
||||||
offset.x += charWidth;
|
offset.x += charWidth;
|
||||||
Shape* shape = new (nothrow) Shape(NULL);
|
Shape* shape = new (nothrow) Shape(NULL);
|
||||||
|
shape->SetName(glyphName.String());
|
||||||
if (!shape || !icon->Shapes()->AddShape(shape)) {
|
if (!shape || !icon->Shapes()->AddShape(shape)) {
|
||||||
delete shape;
|
delete shape;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@ -307,7 +333,7 @@ StyledTextImporter::_Import(Icon* icon, const char *text, text_run_array *runs)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShapeIterator iterator(icon, shape, offset);
|
ShapeIterator iterator(icon, shape, offset, glyphName.String());
|
||||||
if (iterator.Iterate(&glyph) < B_OK)
|
if (iterator.Iterate(&glyph) < B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@ -337,6 +363,9 @@ StyledTextImporter::_AddStyle(Icon *icon, text_run *run)
|
|||||||
delete style;
|
delete style;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
char name[30];
|
||||||
|
sprintf(name, "Color (#%02x%02x%02x)", color.red, color.green, color.blue);
|
||||||
|
style->SetName(name);
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < fStyleCount; i++) {
|
for (int i = 0; i < fStyleCount; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user