r15885 by pierremarc - Got an entire story to be shaped and displayed through many text frames, more or less the end of the prototyping.
scribus-commit
scribus-commit at lists.scribus.net
Tue Nov 16 15:44:21 CET 2010
Author: pierremarc
Date: Tue Nov 16 14:44:21 2010
New Revision: 15885
URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15885
Log:
Got an entire story to be shaped and displayed through many text frames, more or less the end of the prototyping.
Modified:
branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
branches/ScribusOIF/scribus/text/blocklayouter.cpp
branches/ScribusOIF/scribus/text/boxes.cpp
branches/ScribusOIF/scribus/text/glyphstore.cpp
branches/ScribusOIF/scribus/text/glyphstore.h
branches/ScribusOIF/scribus/text/textlayout.cpp
branches/ScribusOIF/scribus/text/textlayout.h
Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15885&path=/branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface_ttf.cpp (original)
+++ branches/ScribusOIF/scribus/fonts/scface_ttf.cpp Tue Nov 16 14:44:21 2010
@@ -796,7 +796,7 @@
stackY = positions[ ( ( gIdx + 1 ) * 2 ) + 1];
glList << curGlyph;
charList << indices[gIdx];
- qDebug()<<"icu"<<text.at(indices[gIdx])<< itemPos + indices[gIdx] << curGlyph.glyph <<curGlyph.xadvance <<curGlyph.yoffset ;
+// qDebug()<<"icu"<<text.at(indices[gIdx])<< itemPos + indices[gIdx] << curGlyph.glyph <<curGlyph.xadvance <<curGlyph.yoffset ;
}
}
icuLE->reset();
Modified: branches/ScribusOIF/scribus/text/blocklayouter.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15885&path=/branches/ScribusOIF/scribus/text/blocklayouter.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/blocklayouter.cpp (original)
+++ branches/ScribusOIF/scribus/text/blocklayouter.cpp Tue Nov 16 14:44:21 2010
@@ -48,7 +48,7 @@
BlockLayouterBase::BlockResult BlockLayouter::layoutJustified(int startPos, int endPos) const
{
// FIXME_OIF
- return BlockLayouterBase::BlockResult(0, 0);
+ return BlockLayouterBase::BlockResult(0, 0, true);
}
// In a first instance we just check it can work: prototyping
@@ -59,13 +59,14 @@
const StoryText * story(m_layout->story());
const ParagraphStyle parStyle(story->paragraphStyle(startPos));
const CharStyle charStyle(parStyle.charStyle());
- const BoxGroup * bg(m_layout->box());
+ const double frameHeight(m_layout->pageItem()->height());
+ bool fitInFrame(true);
double asc(charStyle.font().ascent() * charStyle.fontSize() / 10.0);
double desc(charStyle.font().descent() * charStyle.fontSize() / 10.0);
double y(0.0);
double x(parStyle.leftMargin());
- if(bg->boxCount() > 0)
+// if(bg->boxCount() > 0)
{
y = m_layout->box()->bbox().bottom()
+ story->paragraphStyle(startPos - 1).gapAfter()
@@ -79,6 +80,11 @@
int curPos(startPos);
while(curPos < endPos)
{
+ if(y > frameHeight)
+ {
+ fitInFrame = false;
+ break;
+ }
HBox * line(new HBox);
LineLayouter::ResultSet lineR(m_lineLayouter->layoutLine( curPos, width ));
@@ -132,12 +138,12 @@
curPos = lResult.endPos + 1;
resultBox->addBox(line);
}
- return BlockResult(resultBox, curPos - 1);
+ return BlockResult(resultBox, curPos - 1, fitInFrame);
}
BlockLayouterBase::BlockResult BlockLayouter::layoutRight(int startPos, int endPos) const
{
// FIXME_OIF
- return BlockLayouterBase::BlockResult(0, 0);
+ return BlockLayouterBase::BlockResult(0, 0, true);
}
Modified: branches/ScribusOIF/scribus/text/boxes.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15885&path=/branches/ScribusOIF/scribus/text/boxes.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/boxes.cpp (original)
+++ branches/ScribusOIF/scribus/text/boxes.cpp Tue Nov 16 14:44:21 2010
@@ -32,26 +32,11 @@
void BoxGroup::addBox(Box *b)
{
m_boxes.append(b);
- double bRight(b->x() + b->width());
- double tRight(m_x + m_width);
- double maxRight(qMax(bRight, tRight));
- m_x = qMin(m_x, b->x());
- m_width = maxRight - m_x;
- if(m_type == T_Block)
- {
- double bBottom(b->y() + b->height());
- double tBottom(m_y + height());
- double maxBottom(qMax(bBottom, tBottom));
- m_y = qMin(m_y, b->y());
- m_ascent = qMax(b->ascent(), m_ascent);
- m_descent = (maxBottom - m_y) - m_ascent;
- }
- else
- {
- m_ascent = qMax(b->ascent(), m_ascent);
- m_descent = qMax(b->descent(), m_descent);
- m_y = qMin(m_y, b->y());
- }
+ FRect newRect = bbox().unite(b->bbox());
+ m_y = newRect.y();
+ m_x = newRect.x();
+ m_ascent = qMax(b->ascent(), m_ascent);
+ m_descent = newRect.height() - m_ascent;
qDebug()<<"BoxGroup::addBox"<< b->toString()<<toString();
}
@@ -61,6 +46,7 @@
p->setPen(Qt::green);
p->drawLine(FPoint(x(), y() - m_ascent), FPoint(x()+width(), y() + m_descent));
p->restore();
+ p->moveTo(x(),y());
for (int i=0; i < m_boxes.count(); ++i)
{
m_boxes[i]->render(p, renderOptions);
@@ -425,12 +411,13 @@
void GlyphBox::render(ScPainter* p, const RenderOptions& renderOptions) const
{
const CharStyle& style(m_glyphs->story()->charStyle(m_charStart));
-p->save();
-p->setPen(Qt::lightGray);
+ p->save();
+ p->setPen(Qt::lightGray);
p->setFillMode(ScPainter::None);
p->drawRect(x(), y()-m_ascent, width(), height());
p->restore();
p->save();
+ p->setAntialiasing(true);
p->translate(x(), y());
QString color = style.fillColor();
@@ -472,7 +459,7 @@
}
GlyphLayout* layout = cluster.glyphs();
uint glyph = layout->glyph;
- qDebug() << "render pos"<< cluster.textPosition()<<"glyph" << glyph << "width" << layout->xadvance << "font" << style.font().scName() << "@" << x() << y() ;
+// qDebug() << "render pos"<< cluster.textPosition()<<"glyph" << glyph << "width" << layout->xadvance << "font" << style.font().scName() << "@" << x() << y() ;
if ((renderOptions.showControls) &&
(glyph == style.font().char2CMap(QChar(' ')) || glyph >= ScFace::CONTROL_GLYPHS))
{
Modified: branches/ScribusOIF/scribus/text/glyphstore.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15885&path=/branches/ScribusOIF/scribus/text/glyphstore.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/glyphstore.cpp (original)
+++ branches/ScribusOIF/scribus/text/glyphstore.cpp Tue Nov 16 14:44:21 2010
@@ -80,16 +80,42 @@
return m_items.count() - 1;
}
+void GlyphStore::clear()
+{
+ clearAllItems(0);
+ m_items.clear();
+}
void GlyphStore::clearItem(uint i)
{
itemSetGlyphCount(i, 0);
+ for(int idx(m_items[i].textPosition); idx < m_items[i].textPosition + m_items[i].charCount; ++idx)
+ {
+ m_clusterOffsets.remove(idx);
+ }
}
void GlyphStore::clearAllItems(uint firstItem)
{
+ if(firstItem >= m_items.count())
+ return;
int end = m_items[firstItem].glyphIndex;
+ if(firstItem > 0)
+ {
+ int firstChar = m_items[firstItem].textPosition;
+ QMap<int, int> tmpC;
+ foreach(const int& k, m_clusterOffsets.keys())
+ {
+ if(k == firstChar)
+ break;
+ tmpC.insert(k, m_clusterOffsets.value(k));
+ }
+ m_clusterOffsets = tmpC;
+ }
+ else
+ m_clusterOffsets.clear();
+
m_glyphs.resize(end);
for (int i=firstItem; i < m_items.count(); ++i)
{
@@ -320,8 +346,7 @@
const ItemData& item(m_items[c.m_item]);
int pos = c.m_pos;
int len = m_story->length();
- QMap<int,int>::iterator it(m_clusterOffsets.find(pos));
- it++;
+ QMap<int,int>::iterator it(m_clusterOffsets.lowerBound(pos + 1));
int nextPos = -1;
if(it != m_clusterOffsets.end())
nextPos = it.key();
@@ -373,7 +398,9 @@
Cluster n = next(c);
if (n.isValid())
{
- return n.glyphs() - c.glyphs();
+ uint ret(n.glyphs() - c.glyphs());
+ Q_ASSERT(ret <= item.glyphCount);
+ return ret;
}
else
{
Modified: branches/ScribusOIF/scribus/text/glyphstore.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15885&path=/branches/ScribusOIF/scribus/text/glyphstore.h
==============================================================================
--- branches/ScribusOIF/scribus/text/glyphstore.h (original)
+++ branches/ScribusOIF/scribus/text/glyphstore.h Tue Nov 16 14:44:21 2010
@@ -115,6 +115,8 @@
uint nrOfItems() const { return m_items.count(); }
/// adds a new item for the text starting at pos
uint addItem(int pos, uint len);
+ /// Clear the GlyphStore
+ void clear();
/// removes all glyphs from this item (equivalent to itemSetGlyphCount(i, 0); )
void clearItem(uint i);
/// removes all glyphs from this and all following items
Modified: branches/ScribusOIF/scribus/text/textlayout.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15885&path=/branches/ScribusOIF/scribus/text/textlayout.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/textlayout.cpp (original)
+++ branches/ScribusOIF/scribus/text/textlayout.cpp Tue Nov 16 14:44:21 2010
@@ -327,7 +327,8 @@
if(m_layout)
delete m_layout;
m_layout = new VBox;
- m_layout->moveTo(m_frame->xPos(), m_frame->yPos());
+// m_layout->moveTo(m_frame->xPos(), m_frame->yPos());
+ m_layout->moveTo(0,0);
m_firstInFrame = 0;
const int storyLen = m_story->length();
// a) the caller _MUST_ ensure that previous frame can provide a valid endOfFrame
@@ -337,7 +338,7 @@
{
// if(!m_frame->BackBox->textLayout->isValid())
// m_frame->BackBox->textLayout->render(p, renderOptions);
- m_firstInFrame = m_frame->prevInChain()->textLayout->endOfFrame() + 1;
+ m_firstInFrame = m_frame->prevInChain()->textLayout->endOfFrame();
}
if(m_firstInFrame >= storyLen)
@@ -352,8 +353,8 @@
m_story->charAttributes(i) &= ~TextFlag_ClusterStart;
}
- // reset items for this run. Radical!
- m_story->glyphStore()->deleteItems(m_story->glyphStore()->findItems(m_firstInFrame, storyLen - 1));
+ // reset items for this run until the end of the text. Radical!
+ m_story->glyphStore()->clear();
// We run each paragraph through the block layouter and adjust m_lastInFrame
int parIdx(m_story->nrOfParagraph(m_firstInFrame));
@@ -382,6 +383,12 @@
if(result.lastPos >= 0)
{
m_layout->addBox( result.box );
+ if(!result.fitInFrame)
+ {
+ qDebug()<<"Add Par Box:"<<result.box->toString();
+ m_lastInFrame = result.lastPos;
+ break;
+ }
// FIXME_OIF position the parsep
if(parSep >= 0)
{
Modified: branches/ScribusOIF/scribus/text/textlayout.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15885&path=/branches/ScribusOIF/scribus/text/textlayout.h
==============================================================================
--- branches/ScribusOIF/scribus/text/textlayout.h (original)
+++ branches/ScribusOIF/scribus/text/textlayout.h Tue Nov 16 14:44:21 2010
@@ -88,13 +88,16 @@
{
Box * box;
int lastPos;
- BlockResult(Box * b, int l):
+ bool fitInFrame;
+ BlockResult(Box * b, int l, bool f):
box(b),
- lastPos(l)
+ lastPos(l),
+ fitInFrame(f)
{}
BlockResult(const BlockResult& o):
box(o.box),
- lastPos(o.lastPos)
+ lastPos(o.lastPos),
+ fitInFrame(o.fitInFrame)
{}
};
More information about the scribus-commit
mailing list