本文整理汇总了C++中cairo::RefPtr::set_font_face方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::set_font_face方法的具体用法?C++ RefPtr::set_font_face怎么用?C++ RefPtr::set_font_face使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo::RefPtr
的用法示例。
在下文中一共展示了RefPtr::set_font_face方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int, char**) {
Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
// fill background in white
cr->set_source_rgb(1.0, 1.0, 1.0);
cr->paint();
// draw a little dot at the point where text will be drawn
cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
cr->fill();
// draw the text
cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
cr->set_source_rgb(0.8, 0.2, 0.2);
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(
"Bitstream Charter", Cairo::FONT_SLANT_ITALIC,
Cairo::FONT_WEIGHT_BOLD);
cr->set_font_face(font);
cr->set_font_size(FONT_SIZE);
cr->show_text("cairomm!");
surface->write_to_png("toy-text.png");
return 0;
}
示例2: label
void NodeRenderer::label(const Cairo::RefPtr<Cairo::Context>& cr,
std::list<shared_ptr<Label> >& labels,
AssetCache& cache)
{
// nothing to print
if (s->text.str().size() == 0 || s->font_size <= 0)
return;
cr->save();
cr->set_font_size(s->font_size);
cr->set_font_face(cache.getFont(
s->font_family.str(),
s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL,
s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL
));
Cairo::TextExtents textSize;
cr->get_text_extents(s->text.str(), textSize);
addLabel(labels, location + FloatPoint(0.0, s->text_offset), textSize);
cr->restore();
}
示例3: main
int main(int, char**) {
Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
// fill background in white
cr->set_source_rgb(1.0, 1.0, 1.0);
cr->paint();
// draw a little dot at the point where text will be drawn
cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
cr->fill();
// draw the text
cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
cr->set_source_rgb(0.8, 0.2, 0.2);
Cairo::RefPtr<BoxFontFace> font = BoxFontFace::create();
cr->set_font_face(font);
cr->set_font_size(FONT_SIZE);
cr->show_text("cairomm!");
// Now show it with the toy text API to
// demonstrate how the glyphs match up
cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
cr->set_source_rgba(0.2, 0.2, 0.2, 0.3);
Cairo::RefPtr<Cairo::ToyFontFace> toy_font = Cairo::ToyFontFace::create(
"Bitstream Charter", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_BOLD);
cr->set_font_face(toy_font);
cr->set_font_size(FONT_SIZE);
cr->show_text("cairomm!");
const char* filename = "user-font.png";
try {
surface->write_to_png(filename);
std::cout << "Wrote Image " << filename << std::endl;
return 0;
} catch (const std::exception& e) {
std::cout << "** Unable to write Image " << filename << std::endl;
return 1;
}
}
示例4: renderLabels
void renderLabels(Cairo::RefPtr<Cairo::Context> cr, std::vector<std::pair<string, FloatPoint> >& toPlace) {
cr->save();
cr->set_source_rgba(0.0, 0.0, 0.0, 0.5);
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(DEFAULT_FONT, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_face(font);
cr->set_font_size(120.0);
cr->set_line_width(2.0);
Cairo::TextExtents textSize;
std::list<shared_ptr<Label> > labels;
int i = 0;
std::vector<shared_ptr<Style>> styles;
for (auto& pair : toPlace)
{
string& text = pair.first;
cr->get_text_extents(text, textSize);
shared_ptr<Style> s = boost::make_shared<Style>();
s->text = text;
styles.push_back(s);
FloatPoint center = pair.second + FloatPoint(textSize.width/2.0, textSize.height/2.0);
FloatRect owner = FloatRect(center.x, center.y, center.x, center.y);
FloatPoint origin = pair.second - FloatPoint(textSize.x_bearing, textSize.y_bearing);
shared_ptr<Label> l = boost::make_shared<Label>(FloatRect(pair.second, textSize.width, textSize.height), owner, s->text, s.get(), origin);
cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
cr->stroke();
labels.push_back(l);
}
std::vector<shared_ptr<Label> > placed;
placeLabels(labels, placed);
for (auto& l: placed)
{
cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
cr->move_to(l->box.minX, l->box.maxY);
cr->show_text(l->style->text.str());
cr->fill();
cr->set_source_rgba(1.0, 0.0, 0.0, 0.5);
cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
cr->fill();
}
cr->restore();
}
示例5: renderLabels
void Renderer::renderLabels(const Cairo::RefPtr<Cairo::Context>& cr,
std::vector<shared_ptr<LabelType> >& labels,
AssetCache& cache) const
{
cr->save();
cr->set_line_join(Cairo::LINE_JOIN_ROUND);
for (auto it = labels.rbegin(); it != labels.rend(); it++)
{
const shared_ptr<LabelType>& label = *it;
const Style* s = label->style;
cr->set_font_size(s->font_size);
cr->move_to(label->origin.x, label->origin.y);
cr->set_font_face(cache.getFont(
s->font_family.str(),
s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL,
s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL
));
cr->text_path(label->text.str());
if (s->text_halo_radius > 0.0)
{
cr->set_source_color(s->text_halo_color);
cr->set_line_width(s->text_halo_radius*2.0);
cr->stroke_preserve();
}
cr->set_source_color(s->text_color);
cr->fill();
}
cr->restore();
}
示例6: determineColor
void guiRenderer2D::drawMatrices(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height, bool screenshot) {
cr->scale(m_scaleFactor, m_scaleFactor); // Scale sensor to fit the active window
cr->translate(m_offsetX, m_offsetY); // Center figure on drawable/surface
cr->set_line_width(0.25);
for(uint m = 0; m < m_frameManager->getNumMatrices(); m++) {
matrixInfo &matrix = m_frameManager->getMatrixInfo(m);
// TSFrame* tsFrame = m_frameManager->getCurrentFrame();
TSFrame* tsFrame = m_frameManager->getCurrentFilteredFrame();
for(uint y = 0; y < matrix.cells_y; y++) {
for(uint x = 0; x < matrix.cells_x; x++) {
bool maskedStatic = m_frameManager->getStaticMask(m, x, y);
bool maskedDynamic = m_frameManager->getDynamicMask(m, x, y);
uint cellID = matrix.texel_offset + y * matrix.cells_x + x;
float value = tsFrame->cells[cellID];
if(maskedStatic) {
RGB color = determineColor(value);
// Draw sensor cell rectangle
cr->rectangle(m_rectangleTopLeftX[cellID], m_rectangleTopLeftY[cellID], m_rectangleWidth[cellID], m_rectangleHeight[cellID]);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->stroke_preserve(); // Cell outline
if(maskedDynamic) {
if(value > 0.0) {
cr->set_source_rgb(color.r, color.g, color.b); // Active cells
} else {
cr->set_source_rgb(1.0, 1.0, 1.0); // Inactive cells
}
} else {
cr->set_source_rgb(0.8, 0.8, 0.8); // Disabled cells
}
cr->fill();
}
// Highlight selected cells
if(m_frameManager->isSelected(cellID)) {
cr->rectangle(m_rectangleTopLeftX[cellID], m_rectangleTopLeftY[cellID], m_rectangleWidth[cellID], m_rectangleHeight[cellID]);
cr->set_source_rgba(0.0, 1.0, 0.0, 0.5); // Fill active cells
cr->fill();
}
if(screenshot) {
if(maskedStatic) {
// Print values
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create("LMSans10", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_face(font);
cr->set_font_size(matrix.texel_width/3);
std::ostringstream ss;
ss << value;
std::string valueStr = ss.str();
Cairo::TextExtents te;
cr->get_text_extents(valueStr, te);
cr->move_to(m_matrixCellCenterX[cellID]-te.width/2, m_matrixCellCenterY[cellID]+te.height/2);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->show_text(valueStr);
}
}
}
}
if(!screenshot) {
{
// Print Matrix IDs
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create("LMSans10", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_face(font);
cr->set_font_size(matrix.cells_x*matrix.texel_width);
std::ostringstream ss;
ss << m;
std::string idString = ss.str();
Cairo::TextExtents te;
cr->get_text_extents(idString, te);
cr->move_to(m_newCenterX[m]-te.width/2, m_newCenterY[m]+te.height/2);
cr->set_source_rgba(0.3, 0.3, 0.3, 0.3);
cr->show_text(idString);
}
}
}
}