|
This does clarify some of the questions I would otherwise have asked already. With that, I'll go into the specific scenario I'm dealing with: I'm working on a music notation program, which will be getting its music symbols from a font. (For now it will involve drawing symbols to the screen, so looks like that makes display device contexts the relevant ones.) I have installed the Bravura font, and would like to use it for this purpose. The first difficulty is the proper way to select it. My understanding is that what I installed is an example of what MSDN calls a physical font, and there is no way to select a physical font directly, all font selection instead involving specifying a set of properties one wants the font to have, then allowing Windows to find the physical font that most closely matches those properties from among those available to the device in question. Is that right?
I had no idea what values I would need to specify for most of the parameters of CreateFont in order for the font mapper to find Bravura as a match. The cHeight and cWidth parameters are especially confusing for reasons I'll get back to, but many of the other parameters are too, given that they seem to be text-specific, while my font isn't used for text. So instead I called EnumFonts. I assume it's possible for this function to find more than one match for the given typeface name, but am unsure about the implications of the number of matches it finds. I believe my font should be one that can be scaled freely to different sizes. Would one expect EnumFonts to call the callback specified by the lpProc parameter once for every possible size such a font can be rendered in? Or, if it calls the callback only once (which is what happened for me), what do the lfHeight and lfWidth fields of the LOGFONT struct passed to it indicate, if not that the font can only be rendered at that one (logical-unit) size after all?
I have still more questions after this, but it will be easier to check whether I'm in the right ballpark with what I've said so far first.
modified 7-Sep-18 0:32am.
|
|
|
|
|
There is no requirement to enumerate the font you can just straight ask for it.
I am going to assume you know how to get a device context for your window to display it in.
I am going to assume the font is a TTF font.
If you want to test it just type in any name of a truetype and it should change how any new text sent to the window displays .. try "Gabriola" or something crazy like that and what it does .
#include <tchar.h>
BOOL SetFontToDC(HDC Dc)
{
LOGFONT lf = {0 };
HANDLE TTFHandle;
lf.lfHeight = -16;
lf.lfWeight = FW_NORMAL;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
_tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Bravura"));
TTFHandle = CreateFontIndirect(&lf);
if (TTFHandle != INVALID_HANDLE_VALUE)
{
SelectObject(Dc, TTFHandle);
return TRUE;
}
return FALSE;
}
You get what the indirect is about, it means programatically no user prompts or asking. So this will not ask any questions it will fail quiet if we have done something wrong. On the API that is what any indirect call usually means and yes its a strange terminology as well. Direct is the opposite it means ask the user directly.
There are other options you can ask it for about the font on the LOGFONT structure but none of it is mandatory, 0 for any field means default which is why I zeroed the structure at create.
tagLOGFONTA | Microsoft Docs[^]
In vino veritas
modified 8-Sep-18 0:25am.
|
|
|
|
|
Ah, the crucial thing I didn't realize is that it does no harm to set things one doesn't care about to 0. This is particularly helpful with the width field - I was afraid I was going to have to figure out what ratio of height to width displays the characters without distortion, and use it to calculate what width I need for each desired height, but I've tried a few different height values just now with the width set to 0 and it stays proportional. Excellent.
I held off for a while to see whether I had any more questions - sizing would have been the next issue - but I think I have those all worked out too. Thanks for the help.
|
|
|
|
|
The difference is quite simple. A typeface is a design, like Arial or Times New Roman.
A font is the implementation of a typeface.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I actually like your definition but it won't help you with Windows and it will just cause confusion
Open up notepad ask to change font....
What you call a typeface they call a font, then they have a thing called font style which is "bold", "italic", etc and then a size
Open up Wordpad we have something slightly different ....
Here we have font family, then "normal", "bold", "italic" etc becomes fonts and then a size.
In the programming level for the most part closely ressembles the Wordpad situation.
We have a facename which is generally a typeface (but there are some weird ones like wingdings)
We have a style which is bold, italic, condensed etc
We have a size which may be exact or allow the context to adjust
That is why when trying to understand Windows fonts, it is better to just deal with what you have because much of it isn't consistent even within Windows.
In vino veritas
|
|
|
|
|
Write a program that will provide help with basic unix commands. The program should contain a loop that asks the user to input a unix command or enter quit to stop the program. Your program should recognize at least 6 of the basic unix commands like pwd, etc.). Your program should print out the brief description of the command the user entered. If the user enters a command that your program does not recognize, then print a message to that effect.
You must use the C++ string data type for your input variable.
Hint: use the unix man command to get the brief description for the commands you plan to put in your program. The brief description is the text that appears in the NAME section of the man page, after the command name followed by two hyphens (–). For example:
NAME
pwd -- return working directory name
|
|
|
|
|
No, we don't do your homework. If you've made an honest attempt and are stuck on some detail, come back, show us your code and ask a specific question.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Start with the basics and build on it gradually. The first thing you need is a program that accepts a string from the user and checks to see if is the word "quit". If it is anything else then print "unknown command" and go back and wait for the next input. If it is "quit" then exit the program. Once you have that working you can add the other commands one at a time, testing the program after each one.
|
|
|
|
|
Something is definitely wrong here. This is the most simplest, succinct explanation that could be offered, so why in the crap is it not being taught/understood in the school system? Is it the students or the instructors that are to blame?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Well said.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
I suspect it's a mixture. Some teachers are not so good, some students lack the ability, some are lazy. But I suspect we never hear from the ones who do have good teachers, and ability, and are prepared to try things for themselves.
|
|
|
|
|
I created a socket_raw, the custom protocol type is 0x2328, and I send 0x2328 type data on another machine. The capture packet can be captured, but recvfrom cannot receive it. What should I do? Here is the code received.
struct sockaddr_ll sll;
struct ifreq ifr;
if ((sd = socket (PF_PACKET, SOCK_RAW, htons (0x2328))) < 0) {
perror ("socket() failed to get socket descriptor for using ioctl() ");
exit (EXIT_FAILURE);
}
memset (&ifr, 0, sizeof (ifr));
sprintf (ifr.ifr_name, "eth1");
if (ioctl (sd, SIOCGIFINDEX, &ifr) < 0) {
perror ("ioctl() failed");
return (EXIT_FAILURE);
}
memset (&sll, 0, sizeof (sll));
int sll_len;
sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifr.ifr_ifindex;
sll_len = sizeof(sll);
char buffer[1024];
recvfrom(sd, buffer, sizeof(buffer), 0, (struct sockaddr *)&sll, &sll_len);
|
|
|
|
|
|
recvfrom has no return value, because there is no data, so it is blocking. And if I change 0x2328 to 0x0003, I can receive it.
|
|
|
|
|
Try making it a non-blocking socket. You should then get a status return.
|
|
|
|
|
After I set it to non-blocking, I always returned error code 11, but I didn't find the error message corresponding to 11.
|
|
|
|
|
Could you show the actual code used to obtain the error?
|
|
|
|
|
|
It won't help you with your problem but error code 11 is EGAIN defined in errno.h. It indicates that you should execute the function again until you get data or an error, or give up (time out). It is returned by non-blocking functions when the corresponding blocking function would block.
|
|
|
|
|
int main(int argv, char *argc[])
{
struct ifreq ifr;
struct sockaddr_ll sll;
int sd, sll_len;
sll_len = sizeof(sll);
if ((sd = socket(PF_PACKET, SOCK_RAW, htons(0x2328))) < 0)
printf("create socket failed!\n");
sll.sll_halen = ETH_ALEN;
strcpy(ifr.ifr_name, "ens33");
ioctl(sd, SIOCGIFFLAGS, &ifr);
ifr.ifr_flags |= IFF_PROMISC;
if(fcntl(sd, F_SETFL, O_NONBLOCK) == -1) {
perror("fcntl");
exit(errno);
}
char recvbuf[2048];
sleep(5);
int n_read = recvfrom(sd, recvbuf, 2048, 0, (struct sockaddr *)&sll, &sll_len);
if (n_read <= 0)
{
printf("%d\n", errno);
}
}
I started to cycle data before I hibernate, but I still can't receive it
|
|
|
|
|
I found the reason. Previously, because send and recv were sent and received on the same network card, it could not be received.
|
|
|
|
|
Fine to hear that.
I do know that it does not work on the same interface. But you wrote in your initial post that you are sending from another machine so that I thought it must be something else.
|
|
|
|
|
I am trying to calculate sum of fibonacci series.
Struct arg is defined in header file as follows
struct args {
int number;
int result;
};
args user_arguments = { 10, 0 };
void fibonacci (void* arguments)
{
args* local_args = (args*) arguments;
printf("local_args->number = %d\n", local_args->number);
if (local_args->number <= 1) {
local_args->result= 1;
return;
}
int a = (local_args->number)-1;
int b = (local_args->number)-2;
local_args->result =fibonacci(&a) + fibonacci(&b)
return local_args->result;
Above function is called from the function below. createPackage is a function provided by another library which gonna execute fabonacci function.
void WorkPackage(void*) {
createPackage(fibonacci, &user_arguments);
printf("Sum of fabonacci sequence is %d ", args->result) }
While compiling, It gives the following error
invalid operands of types ‘void’ and ‘void’ to binary ‘operator+’
Please help in pointing what am i doing wrong here??
|
|
|
|
|
You are trying to add two operands of the type void (fibonacci(&a)and fibonacci(&b)) :
meerokh wrote: local_args->result =fibonacci(&a) + fibonacci(&b)
and the compiler doesn't know how to do it!
|
|
|
|
|
How can i calculate the sum and add it back to struct variable??
|
|
|
|
|