void mitk::pa::Vector::Randomize(double xLowerLimit, double xUpperLimit, double yLowerLimit, double yUpperLimit, double zLowerLimit, double zUpperLimit, std::mt19937* rng) { std::uniform_real_distribution<> rangeX(xLowerLimit, xUpperLimit); std::uniform_real_distribution<> rangeY(yLowerLimit, yUpperLimit); std::uniform_real_distribution<> rangeZ(zLowerLimit, zUpperLimit); m_Vector.SetElement(0, rangeX(*rng)); m_Vector.SetElement(1, rangeY(*rng)); m_Vector.SetElement(2, rangeZ(*rng)); }
void Line::moveToNextPage(BlockList& floats, double minX, double maxX, const WTextRenderer& renderer) { for (unsigned i = 0; i < blocks_.size(); ++i) { Block *b = blocks_[i]; if (b->isFloat()) Utils::erase(floats, b); } PageState ps; ps.floats = floats; ps.page = page_; Block::clearFloats(ps); page_ = ps.page; floats = ps.floats; double oldY = y_; y_ = 0; x_ = minX; ++page_; BlockList blocks = blocks_; blocks_.clear(); Range rangeX(x_, maxX); Block::adjustAvailableWidth(y_, page_, floats, rangeX); x_ = rangeX.start; maxX = rangeX.end; for (unsigned i = 0; i < blocks.size(); ++i) { Block *b = blocks[i]; if (b->isFloat()) { b->layoutFloat(y_, page_, floats, x_, height_, minX, maxX, false, renderer); reflow(b); } else { for (unsigned j = 0; j < b->inlineLayout.size(); ++j) { InlineBox& ib = b->inlineLayout[j]; if (ib.y == oldY && ib.page == page_ - 1) { if (ib.x != LEFT_MARGIN_X) { ib.x = x_; x_ += ib.width; } ib.page = page_; ib.y = y_; } } } blocks_.push_back(b); } }
void Line::finish(AlignmentFlag textAlign, BlockList& floats, double minX, double maxX, const WTextRenderer& renderer) { /* * First right-trim right most text. */ for (unsigned i = 0; i < blocks_.size(); ++i) { Block *b = blocks_[blocks_.size() - 1 - i]; if (!b->isFloat()) { if (b->type() != DomElement_LI && b->isText()) { bool done = false; for (unsigned j = 0; j < b->inlineLayout.size(); ++j) { InlineBox& ib = b->inlineLayout[b->inlineLayout.size() - 1 - j]; if (ib.utf8Count > 0) { char lastChar = b->text()[ib.utf8Pos + ib.utf8Count - 1]; if (Block::isWhitespace(lastChar)) { --ib.utf8Count; ib.width -= ib.whitespaceWidth; } done = true; break; } } if (done) break; } else break; } } Range rangeX(minX, maxX); Block::adjustAvailableWidth(y_, page_, floats, rangeX); /* Compute total width and total white space width */ double whitespace = 0; double content = 0; std::vector<InlineBox *> boxes; for (unsigned i = 0; i < blocks_.size(); ++i) { Block *b = blocks_[i]; if (b->isFloat()) b->layoutFloat(y_ + height_, page_, floats, minX, 0, minX, maxX, false, renderer); else { for (unsigned j = 0; j < b->inlineLayout.size(); ++j) { InlineBox& ib = b->inlineLayout[j]; if (ib.y == y_ && ib.page == page_) { std::string va = b->cssProperty(PropertyStyleVerticalAlign); if (va == "top") ib.y = y_; else if (va == "bottom") ib.y = y_ + height_ - ib.height; else ib.y += baseline_ - ib.baseline; if (ib.x != LEFT_MARGIN_X) { boxes.push_back(&ib); content += ib.width; ib.whitespaceCount = 0; if (b->isText()) { for (int k = 0; k < ib.utf8Count; ++k) { if (Block::isWhitespace(b->text()[ib.utf8Pos + k])) ++ib.whitespaceCount; } content -= ib.whitespaceWidth * ib.whitespaceCount; whitespace += ib.whitespaceWidth * ib.whitespaceCount; } } else { /* Positioned in the margin */ ib.x = rangeX.start - ib.width; } } } } } double spaceFactor = 1.0; switch (textAlign) { case AlignLeft: break; case AlignRight: rangeX.start = rangeX.end - content - whitespace; break; case AlignCenter: rangeX.start += (rangeX.end - rangeX.start - content - whitespace)/2; break; case AlignJustify: if (!lineBreak_) { double remaining = rangeX.end - rangeX.start - content; if (whitespace > 0) spaceFactor = remaining / whitespace; } break; default: LOG_ERROR("unsupported text-align attribute: " << (int)textAlign); } double x = rangeX.start; for (unsigned i = 0; i < boxes.size(); ++i) { InlineBox& ib = *boxes[i]; ib.x = x; double contentWidth = ib.width - ib.whitespaceWidth * ib.whitespaceCount; ib.whitespaceWidth *= spaceFactor; ib.width = contentWidth + ib.whitespaceWidth * ib.whitespaceCount; x += ib.width; } blocks_.clear(); }