magicgui icon indicating copy to clipboard operation
magicgui copied to clipboard

DirectWrite: CreateFontFaceFromHDC() failed

Open hjroyal opened this issue 1 year ago • 5 comments

1. Environment :

  • OS: [Windows11]
  • backend: [PyQt5 5.11.5]
  • magicgui version [0.8.3]
  • python 3.11.5

2. Problem: I followed the tutorial on the official website and tried to run the following example code to get an error.

DirectWrite: CreateFontFaceFromHDC() failed (指示输入文件 (例如字体文件) 中的错误。) for QFontDef(Family="MS Sans Serif", pointsize=12, pixelsize=16, styleHint=5, weight=400, stretch=100, hintingPreference=0) LOGFONT("MS Sans Serif", lfWidth=0, lfHeight=-16) dpi=96

# test.py

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvas

from magicgui import magicgui

x = np.linspace(0, 5, 256)
y = np.linspace(0, 5, 256)[:, np.newaxis]
data = np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)

mpl_fig = plt.figure()
ax = mpl_fig.add_subplot(111)
(line,) = ax.plot(data[123])  # linescan through the middle of the image


@magicgui(position={"widget_type": "Slider", "max": 255}, auto_call=True)
def f(position: int):
    """Function demonstrating magicgui combined with matplotlib."""
    line.set_ydata(data[position])
    line.figure.canvas.draw()


# rather than using the Container.append (`f.append`) ...
# grab the native layout and add the QWidget to it
f.native.layout().addWidget(FigureCanvas(mpl_fig))

f.show(run=True)

3. Actions: pip install magicgui pip install PyQt5 run test.py

hjroyal avatar Jun 21 '24 12:06 hjroyal

hi @hjroyal, it's hard to tell what this issue is. is this a bug report? if so, please tell me what code you ran to get this error, and if that DirectWrite line is an exception you received, please give the full traceback

tlambert03 avatar Jun 21 '24 13:06 tlambert03

Yes. Thank you for your reply. I updated my question and I guess it's a Windows 11 problem.

hjroyal avatar Jun 23 '24 16:06 hjroyal

thank you. Ultimately, this is likely to be a broader Qt problem for you, and not a magicgui issue. However, if you can give me the full error message, including the traceback (i.e. NOT just the bit including DirectWrite: CreateFontFaceFromHDC() ... but rather the entire error message, including file names and line numbers) I might be help a bit more

tlambert03 avatar Jun 23 '24 16:06 tlambert03

@hjroyal I think it's a windows x Qt issue. It's not an error but a log output by Qt at C++ level.

hanjinliu avatar Jun 24 '24 14:06 hanjinliu

It's not an error but a log output by Qt at C++ level.

ahh, is that true @hjroyal? Does the example otherwise work? You're just seeing this printed to your console?

tlambert03 avatar Jun 24 '24 14:06 tlambert03

It's not an error but a log output by Qt at C++ level.

ahh, is that true @hjroyal? Does the example otherwise work? You're just seeing this printed to your console?

How to block this output, otherwise the application will become unsightly

yinsel avatar Dec 17 '24 18:12 yinsel

How to block this output, otherwise the application will become unsightly

I'm not entirely sure, and it's hard to test because I can't reproduce it. But this is ultimately a Qt issue, and not a magicgui issue. So, if Qt is unable to fonts somehow in your system you would need to solve this at a lower level. The most useful thing you could do is reduce this to a bare minimum example, so we can determine what exactly is calling CreateFontFaceFromHDC ... it's not magicgui. it might be matplotlib? it might be lower down in Qt C++ layer?

tlambert03 avatar Dec 17 '24 18:12 tlambert03

如何阻止此输出,否则应用程序将变得难看

我不完全确定,而且很难测试,因为我无法重现它。但这最终是一个 Qt 问题,而不是一个 magicgui 问题。因此,如果 Qt 无法以某种方式在您的系统中使用字体,您将需要在较低级别解决这个问题。你能做的最有用的事情是将其简化为一个最少的示例,这样我们就可以确定到底是什么在调用 ...它不是 magicgui。可能是 matplotlib?它可能在 Qt C++ 层的较低位置?CreateFontFaceFromHDC

No, I am using the simplest example in the document

yinsel avatar Dec 17 '24 18:12 yinsel

i'm sorry I can't read that. can you please paste the exact code you're running, and the exact output you're seeing?

tlambert03 avatar Dec 17 '24 18:12 tlambert03