How many fonts are available in Prawn? - prawn

I've been randomly trying fonts in Prawn, for Ruby.
For Example:
Times New Roman - Yes
Palatino Linotype - No
Is there a list of which fonts are available and which aren't?

There's a list of default fonts in the code, at lib/prawn/font/afm.rb (version 1.0.0.rc1):
module Prawn
class Font
class AFM < Font
BUILT_INS = %w[ Courier Helvetica Times-Roman Symbol ZapfDingbats
Courier-Bold Courier-Oblique Courier-BoldOblique
Times-Bold Times-Italic Times-BoldItalic
Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique ]

14 fonts are available by default: Courier, Helvetica, Symbol, Times and ZapfDingbats in various bold and italic forms.
In nearly every case I'd recommend using the font() method to load an external truetype font of your choosing. This has the added benefit of give you the option to use non latin characters.
Short answer: there's no list, just use TTF.

Related

React change string to component (multiple)

I want to make custom grammar like Wiki and how can I do it in React and without dangerouslySetInnerHTML?
For example:
"hello this is simple string [linkToSomewhere] {this is where bold goes}"
becomes
<div>
hello this is simple string <Link where="linktoSomewhere"/> <Bold string="this is where bold goes"/>
</div>
like this
I found way to parse custom markdown to array but found no way to insert it as react component array is like
link[0] = "linkToSomewhere"
bold[0] = "this is where Bold goes"
Thank you in advance!
There are a few Markdown libraries available for React. Check out:
react-markdown: https://rexxars.github.io/react-markdown/
react-remarkable: https://github.com/acdlite/react-remarkable
And here's a whole host of other libraries that can translate your Markdown document into a nicely rendered HTML: https://react.rocks/tag/Markdown
And in order to learn the Markdown syntax, there are a few cheat sheets available, such as:
http://assemble.io/docs/Cheatsheet-Markdown.html
https://guides.github.com/pdfs/markdown-cheatsheet-online.pdf

adding colour in a django models.TextField

I have a model in django:
introduction = models.TextField(null=False, blank=False)
When writing in the text field I want the colour of the middle section to be different from the rest. Any ideas how I do this how to set colours in the textfield?
I'm not sure I get what you mean by 'middle section', but regardless, this would have to be done in client-side since what you want is to manipulate something like the color of a certain TextField. You could do it by using the CSS color properties or even Javascript.
give your textfield an identifier in your html code ,
like, id="tf"
then css will be
#tf{
color : #aaaaaa;
}
write your color code in place of #aaaaaa.

Achieve letter-spacing in RaphaelJs

Is there a way to set letter-spacing in raphael js text? It can be done easily in CSS, how can I do it in raphael? Any hacks would also do..
Paper.print() has a letter-spacing attribute:
var txt = r.print(10, 50, "O HAI", r.getFont("Comic Sans"), 30, 'middle', 1).attr({fill: "#fff"});
^
this is the letter spacing
See the docs on that.
Note that this needs "cufon-style" font files to be included and will render a non-selectable path object instead of real text.
It can be done with normal css. take a look here : http://tutorials.jenkov.com/svg/text-element.html . The css is applied to svg too.
Here's a live demo that shows svg text with letter-spacing.

QT - multi-select

I would like to create a search-type text field in QT that can contain both standard text as well as what I would call "tags"... basically additional search terms that are individually highlighted and separated. I envision this looking like the multi-select in "Chosen" (Javascript library). http://harvesthq.github.com/chosen/
I have been unable to find anything similar through searching. It also seems that the standard QT text box types are not designed to have "sub-widgets".
It appears that QTextEdit supports HTML... that might be a possiblity... but the docs are not very clear to me as what is supported in terms of CSS (which I think would be required to get the desired formatting). http://doc.qt.io/qt-5/qtextedit.html#html-prop
Its funny... I got to the bottom of this submission page and realized I have to tag this (this is my first SO question)... This tag-adder box is almost exactly what I want!
There is no ready-to-use soultion that I know.
If I were to try implementing it, I would definitely use widget with layout, in which there are two types of child widgets: LineEdits (borderless to look like actual part of bigger widget) and buttons - code managing line edit changes would simply add new buttons before or after and if necesary splited linedit into tw with button between. This way is not interfering with qt programers intentions on how to use widgets and how to make them all fit together in one style.
If you want you can use custom widgets instead of buttons to provide remove icon.
As I wrote in my comment - if i have a bit more time I will try to make something like that myself.
Here is a very simple implementation of putting buttons in a QLineEdit as a user types, written in Python:
from PySide.QtCore import *
from PySide.QtGui import *
class Entry(QLineEdit):
def __init__(self):
QLineEdit.__init__(self)
self.buttons = []
self.backupText = ''
self.textEdited.connect(self.on_change)
self.layout = QHBoxLayout()
self.setLayout(self.layout)
self.layout.addStretch()
marginz = QLabel(' ')
marginz.show()
margin = marginz.width()
marginz.hide()
self.layout.setContentsMargins(margin, margin, margin, margin)
def on_change(self):
if self.text()[-1] == ' ' and not self.text().endswith(' '):
if len(self.text()) > len(self.backupText):
self.setText(self.text() + ' ')
self.buttons.append(QPushButton(self.text().split()[-1]))
self.layout.insertWidget(self.layout.count()-1, self.buttons[-1])
else:
self.setText(self.text()[0:-1])
self.buttons[-1].hide()
del self.buttons[-1]
self.backupText = self.text()
app = QApplication([])
window = QMainWindow()
window.setStyleSheet(
'QPushButton {border: 1px solid gray; background: lightgray; color: black;}')
entry = Entry()
window.setCentralWidget(entry)
window.show()
app.exec_()
It creates a QHBoxLayout and adds a button to it for each word you type, and takes the button away when you get rid of the word.
If you want to put a close button inside of each of the sub-widgets, you can make a custom widget for that too.
EDIT
As j_kubik's comment stated, systems with wide-margin buttons would cause the tag buttons to overlap the text a user is currently typing. I have modified the code to enforce the margins of the buttons inserted (with stylesheets), added an extra space for each space the user types, and set the QHBoxLayout's contentsMargins to be the same width as a space (""). Now the buttons will not overlap the text inserted.

How to create a bold, red text label in Qt?

I want to write a single, bold red line in my application using Qt.
As far as I understand, I would create a QLabel, set its textFormat to rich text and give it a rich text string to display:
QLabel *warning = new QLabel;
warning->setTextFormat(Qt::RichText);
warning->setText("{\\rtf1\\ansi\\ansicpg1252 {\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;} {\\colortbl;\\red255\\green0\\blue0;} \\f0 \\cf0 this is bold red text}");
I tested this rich text string in a rich text editor and it displays fine.
But Qt displays the whole string with all braces, keywords and backslashes instead of "this is bold red text". What am I doing wrong?
Thank you for your help.
Try using HTML formatting: <b><font... etc </b>.
Qt Designer does it like this: <span style=" font-size:8pt; font-weight:600; color:#aa0000;">TextLabel</span>
You can use Qt StyleSheets and set the styleSheet property of QLabel
warning->setStyleSheet("font-weight: bold; color: red");
Qt supports most CSS styles on its QWidget-derived classes. You don't need to set the text format to Qt::RichText for this to work.
Qt uses a simple HTML subset for formatting.
You can also do it programmatically using the settext function. Something like this:
QString labelText = "<P><b><i><font color='#ff0000' font_size=4>";
labelText .append("Text what u want to display");
labelText .append("</font></i></b></P></br>");
QLabel label->setText(labelText);
You can do it in a single line as well.