find font of characters in a string

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

osric
New php-forum User
New php-forum User
Posts: 6
Joined: Sun Mar 17, 2013 6:41 am

find font of characters in a string

Postby osric » Sun Mar 17, 2013 6:46 am

I have a long string with characters of 7 different fonts. I need to sort the characters into 7 lists, each of the same font. How can I code this please?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: find font of characters in a string

Postby seandisanti » Mon Mar 18, 2013 8:33 am

you should start by trying. if that fails, you should come back and ask for help by showing what you tried, and what the result was. and probably not a horrible idea to show the string in question. If you want someone to do your homework you should at least show them the question.

osric
New php-forum User
New php-forum User
Posts: 6
Joined: Sun Mar 17, 2013 6:41 am

Re: find font of characters in a string

Postby osric » Mon Mar 18, 2013 9:20 am

you should start by trying. if that fails, you should come back and ask for help by showing what you tried, and what the result was. and probably not a horrible idea to show the string in question. If you want someone to do your homework you should at least show them the question.


Ouch! That's a slap on the wrist.

I have not found any help on the Internet to this question. All help seems to be focussed on checking whether a particular font is supported by the browser, which is no use to me.

I have tried to upload a file showing the string as an attachment, but can't do it -- I get the message "the extension doc not allowed" (or rtf or txt). So what do you suggest?

So to restate the problem -- I have a string containing characters with 7 different fonts. How do I make a list of the characters in each font? Is this possible to do in PHP?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: find font of characters in a string

Postby seandisanti » Mon Mar 18, 2013 9:35 am

i suggest researching how to read rich text with php.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: find font of characters in a string

Postby johnj » Mon Mar 18, 2013 9:56 pm

.....I have a string containing characters with 7 different fonts. How do I make a list of the characters in each font? Is this possible to do in PHP?....


Not a slap..... BUT you should first understand what you are trying to do.
PHP is a server side scripting langauge and the issues related to font happen on the client side, on the presentation side - in your browser.

You need to use javascript/jquery and maybe css to detect the font, make a list of it and sent it to php (maybe using ajax).

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: find font of characters in a string

Postby johnj » Mon Mar 18, 2013 9:58 pm


osric
New php-forum User
New php-forum User
Posts: 6
Joined: Sun Mar 17, 2013 6:41 am

Re: find font of characters in a string

Postby osric » Tue Mar 19, 2013 12:34 am

Not a slap..... BUT you should first understand what you are trying to do.
PHP is a server side scripting langauge and the issues related to font happen on the client side, on the presentation side - in your browser.


Thanks for the input. The characters of different font are not on a webpage -- they are in a Word file. The php program loads the contents of the file. As it loads the characters I want it to sort them by their font.

In other words the program should load the characters and then look at them one by one to determine its font and then put the character into an appropriate array (or string).

If the file contained a list of numbers and I wanted to load them and sort them according toy whether they were odd or even, the programming is easy. Why am I having such trouble in finding a way to handle the fonts?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: find font of characters in a string

Postby seandisanti » Tue Mar 19, 2013 7:09 am

your best options are either to look for a way to read rich text with php as suggested before, or open it in word and save it out to html. if it preserves your formatting as it should, there are several easy ways to go from there

osric
New php-forum User
New php-forum User
Posts: 6
Joined: Sun Mar 17, 2013 6:41 am

Re: find font of characters in a string

Postby osric » Tue Mar 19, 2013 10:25 am

your best options are either to look for a way to read rich text with php as suggested before, or open it in word and save it out to html. if it preserves your formatting as it should, there are several easy ways to go from there


There's no problem in saving my multi-font string in a .htm document and then reading it with php code. Nor in viewing the source to reveal the characters of the string with their respective fonts. But this is a far cry from reading the characters one by one from the 'htm document, organising them according to font and displaying the result.

I can't believe that the latter is impossible -- but at the same time I don't know how to do it, and nor it seems does anyone else :(

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: find font of characters in a string

Postby johnj » Wed Mar 20, 2013 1:25 am

Thanks for the input. The characters of different font are not on a webpage -- they are in a Word file. The php program loads the contents of the file. As it loads the characters I want it to sort them by their font.


It does not matter whether it is in a web page or word file. If it is a word file, as suggested, please convert your input to rtf and search for the font type using php

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: find font of characters in a string

Postby seandisanti » Wed Mar 20, 2013 7:12 am

osric wrote:
nor it seems does anyone else :(
Just because im not doing your homework doesn't mean i can't.

osric
New php-forum User
New php-forum User
Posts: 6
Joined: Sun Mar 17, 2013 6:41 am

Re: find font of characters in a string

Postby osric » Thu Mar 21, 2013 1:07 am

your best options are either to look for a way to read rich text


I successfully read a rtf file but the rtf coding is impenetrable and thus this route did not prove useful.

I then read the source of a htm file and the coding here is understandable, if lengthy. For example:
style='font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";mso-fareast-theme-font:minor-fareast;
color:black'>R</span><span style='font-family:Arial;mso-fareast-font-family:
"Times New Roman";mso-fareast-theme-font:minor-fareast;color:black'>R</span><span


I copied and pasted this coding into a text file and wrote a program to go through the text file, seek "Times New Roman" and then pick out the character between > and < that followed. Then do the same with Arial…

So I got the end result I wanted but not the way I wanted to do it. I was looking for (and still am looking for) a method that reads the character in a .doc file (or .rtf file) recognises the font and puts the character in an array of that type of font. I think I have to repeat my earlier assertion that I believe such a method must exist but nobody can tell me what it is. This time I will smile :)

Thank you to all who have contributed and helped.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: find font of characters in a string

Postby seandisanti » Thu Mar 21, 2013 11:50 am

If you're talking about an ocr that just recognizes the fonts, it's possible, but not the best solution any way you look at it. It's more work, would work a lot more slowly, and would be limited to the fonts that you're able to teach your program.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: find font of characters in a string

Postby johnj » Thu Mar 21, 2013 9:30 pm

... I was looking for (and still am looking for) a method that reads the character in a .doc file (or .rtf file) recognises the font and puts the character in an array of that type of font. I think I have to repeat my earlier assertion that I believe such a method must exist but nobody can tell me what it is....


According to me what has been answered here is close to the best that PHP can do. You may want to use a programming language like Java or C# or something else which is more powerful to read doc format. I did tell you many times that PHP is a server side scripting language.

osric
New php-forum User
New php-forum User
Posts: 6
Joined: Sun Mar 17, 2013 6:41 am

Re: find font of characters in a string

Postby osric » Sat Mar 23, 2013 1:53 am

It seems to me that the problem I faced is that there is no asci ii code to represent the type of font and its size. Instead these parameters have to be written out to precede each character. For example the coding in a .htm page to represent the character ‘E’ in Arial is this mouthful:

<spanstyle='font-size:10.0pt;font-family:Arial;mso-bidi-font-family:Arial'>E </span>

In an .rtf document the coding is even more abstruse, including something like <pannose930402020402> to represent the font and its size.

In practice, the Browser or Word software seeks out these coded messages, interprets them and displays the type of font, and its size, accordingly for the letter(s) that follow. This is all done rapidly in the background and we don’t see it happening, we just get the result.

So when I started with my string containing characters with seven different fonts, I was in cloud cuckoo land when I thought I could read a character and at the same time know its font type and size. I ultimately realized that the solution was to write a PHP program that would read the parameters that precede each character, compare them to a master list to determine which array the letter should be placed in and then to pick up the character and put it in that array.

Did my program have to be written in PHP? No, not at all. Python, C, Java or Javascript would have done equally well. But I like programming in PHP, I like the expressions of the language and I like the fact that my programs can be run at my website.

Why did I want to analise the string of different fonts? Because the string was a cryptogram that I was trying to solve (and have now solved) and analysis of the fonts was an essential part of finding the solution.

I hope this little dissertation may be of use to anyone else who wants to muck around with fonts and is approaching this task for the first time.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests