我正在尝试在python ReportLab中添加一个字体,以便我可以将它用于函数.该函数使用canvas.Canvas在PDF中绘制一堆文本,没什么复杂的,但我需要为布局问题添加固定宽度的字体.
当我尝试使用我能找到的小信息来注册字体时,这似乎有效.但是当我试图从我的Canvas对象中调用.addFont('fontname')时,我一直在努力
"PDFDocument实例没有属性'addFont'"
该功能是否未实施?如何访问除.getAvailableFonts中列出的10个左右的默认字体以外的字体?谢谢.
我正在尝试制作的一些示例代码:
from reportlab.pdfgen import canvas
c = canvas.Canvas('label.pdf')
c.addFont('TestFont') #This throws the error listed above, regardless of what argument I use (whether it refers to a font or not).
c.drawString(1,1,'test data here')
c.showPage()
c.save()
Run Code Online (Sandbox Code Playgroud)
要注册字体,我试过了
from reportlab.lib.fonts import addMapping
from reportlab.pdfbase import pdfmetrics
pdfmetrics.registerFont(TTFont('TestFont', 'ghettomarquee.ttf'))
addMapping('TestFont', 0, 0, 'TestFont')
Run Code Online (Sandbox Code Playgroud)
其中'ghettomarquee.ttf'只是一个随意的字体.
我在用Hadoop在$ HADOOP_LOG_DIR产生太多的日志文件的问题/ userlogs(Ext3文件系统只允许32000子目录),它看起来像这个问题,同样的问题:在Hadoop中的MapReduce错误
我的问题是:有没有人知道如何配置Hadoop滚动日志目录或以其他方式防止这种情况?我试图避免只设置"mapred.userlog.retain.hours"和/或"mapred.userlog.limit.kb"属性,因为我想实际保留日志文件.
我也希望在log4j.properties中配置它,但是看看Hadoop 0.20.2源代码,它直接写入日志文件而不是实际使用log4j.也许我不明白它是如何完全使用log4j的.
任何建议或澄清将不胜感激.
我有一个描述为(startX,startY)到(anchorX,anchorY)并使用控制点(controlX,controlY)的二次贝塞尔曲线.
我有两个问题:
(1)我想根据x点确定该曲线上的y点.
(2)然后,在我的贝塞尔给予线段(由二个中继点我贝塞尔曲线(运行startx" startY",anchorX上定义" anchorY")),我想知道的是线段的控制点这样它就会与原始贝塞尔完全重叠.
为什么?我想要这些信息进行优化.我画了许多水平贝塞尔.当beziers大于屏幕时,性能会受到影响,因为渲染引擎最终渲染超出了可见范围.这个问题的答案将让我只渲染可见的东西.
我是BlackBerry编程的初学者,我需要在我的应用程序中用自定义菜单替换默认菜单(当你按下菜单按钮时).最好的描述是我想要与BlackBerry的WeatherEye应用程序相同的结果...
alt text http://www.blackberrybing.com/resource/pics/201002/WeatherEye-OS-45.jpg
我知道如何创建默认菜单,但这个我不知道!谢谢,
我正在使用C#和HtmlAgilityPack,我可以选择id为foo的div
var foos = from foo in htmlDoc.DocumentNode.Descendants("div")
where foo.Id == "foo"
select foo;
Run Code Online (Sandbox Code Playgroud)
但是如何用一类条选择div呢?
我正在尝试创建一个通用方法,该方法将读取类的属性并在运行时返回该值.我该怎么做?
注意:DomainName属性属于DomainNameAttribute类.
[DomainName("MyTable")]
Public class MyClass : DomainBase
{}
Run Code Online (Sandbox Code Playgroud)
我想要生成的内容:
//This should return "MyTable"
String DomainNameValue = GetDomainName<MyClass>();
Run Code Online (Sandbox Code Playgroud) 我正在为Rails应用程序创建测试数据.如何在YAML中定义日期时间字段的值?
我正在使用Java从Web服务器下载zip文件但不知何故我在每个文件中丢失大约2kb.我不知道为什么相同的代码可以与其他格式一起使用,例如text,mp3和extra.任何帮助表示赞赏?这是我的代码.
public void download_zip_file(String save_to) {
try {
URLConnection conn = this.url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("content-type", "binary/data");
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(save_to + "tmp.zip");
byte[] b = new byte[1024];
int count;
while ((count = in.read(b)) > 0) {
out.write(b, 0, count);
}
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用GDI +,我正在使用的图像是一个1bbp的图像.我想做的是在图像上绘制一个矩形,该矩形下的所有内容都将被反转(白色像素将变为黑色,黑色像素变为白色).
我见过的所有示例代码都是针对8位RGB色阶图像,我不认为他们使用的技术对我有用.
这是我到目前为止的代码.这是父控件,其中一个Epl2.IDrawableCommand
将是执行反转的命令.
public class DisplayBox : UserControl
{
(...)
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
(...)
using (Bitmap drawnLabel = new Bitmap((int)((float)Label.LabelHeight * _ImageScaleFactor), (int)((float)Label.LableLength *(int) _ImageScaleFactor), System.Drawing.Imaging.PixelFormat.Format1bppIndexed))
{
using (Graphics drawBuffer = Graphics.FromImage(drawnLabel))
{
(...)
foreach (Epl2.IDrawableCommand cmd in Label.Collection)
{
cmd.Paint(drawBuffer);
}
(...)
}
}
}
}
}
public class InvertArea : IDrawableCommand
{
(...)
public Rectangle InvertRectangle {get; set;}
public void Paint(Graphics g)
{
throw new NotImplementedExecption();
}
}
Run Code Online (Sandbox Code Playgroud)
我应该Paint(Graphic g) …
我正在创建一个应用程序,它包含两个静态库和一个可执行文件.
让我们调用两个静态库:libusefulclass.a libcore.a
和应用程序:myapp
libcore实例化并使用libusefulclass中定义的类(让我们称之为UsefulClass)
现在,如果我按以下方式链接应用程序:
g++ -m64 -Wl,-rpath,/usr/local/Trolltech/Qt-4.5.4/lib -o myapp src1.o src2.o srcN.o -lusefulclass -lcore
Run Code Online (Sandbox Code Playgroud)
链接器抱怨找不到libusefulclass中的方法:
undefined reference to `UsefulClass::foo()'
Run Code Online (Sandbox Code Playgroud)
等等
我找到了一个解决方法:如果UsefulClass也在可执行文件本身的源文件中实例化,则应用程序链接没有任何问题.
我的问题是:是否有更简洁的方法使libcore引用libusefulclass中定义的方法,或者静态库只是无法相互链接?
TIA
PS:如果重要:使用Qt在C++中开发应用程序,但我觉得这不是Qt问题,而是一般的库问题.