APIs to retrieve font-family information for text nodes in mozilla embed using C++?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

APIs to retrieve font-family information for text nodes in mozilla embed using C++?

srivani
Hello,

I am working with mozilla embed and want to use the HTML rendering
engine to get ordered chunks of text with font-family info and any
other style info attached to the text nodes in the DOM that are used
during rendering the text.

I've tried navigating the sources, to find if there are any c++ API to
achieve this.

I have found an API "GetStyleDataExternal" that can be called on
nsIFrame

const nsStyleStruct* pStyle = pIFrame-
>GetStyleDataExternal(eStyleStruct_Font); //here pIFrame is of type
nsIFrame*

Is there any API that I can use on text nodes(of type nsITextContent)
to get the associated font-family info)?


Searching in mozilla.dev.tech.layout, I found a response to a similar
query which mentioned something like:

document.defaultView.getComputedStyle(node, "").fontFamily
should work (translated into the language of your choice, of course).

However I could not find any equivalent API in c++ for getting the
font-family info out of a text node(or text content node).

Does anyone have an idea about any such API?

Any information or pointer to the right things to look for in the code
are welcome :-)

Thanks,
-srivani

_______________________________________________
dev-embedding mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-embedding
Reply | Threaded
Open this post in threaded view
|

Re: APIs to retrieve font-family information for text nodes in mozilla embed using C++?

Eli Friedman
First off, please try to avoid cross-posting (if you're not sure where
to post, just pick one group and go with it.).

srivani wrote:
> document.defaultView.getComputedStyle(node, "").fontFamily
> should work (translated into the language of your choice, of course).
>
> However I could not find any equivalent API in c++ for getting the
> font-family info out of a text node(or text content node).

Translated into the language of your choice:
nsCOMPtr<nsIDOMDocumentView> docView = do_QueryInterface(document);
nsCOMPtr<nsIDOMAbstractView> defaultView;
docView->GetDefaultView(getter_AddRefs(defaultView));
nsCOMPtr<nsIDOMViewCSS> cssView = do_QueryInterface(defaultView);
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
cssView->GetComputedStyle(element, "", getter_AddRefs(cssDecl));
nsString fontFamily;
cssDecl->GetPropertyValue("font-family", fontFamily);
where document is an nsIDOMDocument and element is an nsIDOMElement.

(uncompiled/tested; it's at least close to correct, though.)

Of course, this won't actually tell you what font ends up being used.
Font selection is buried deep in the graphics code, and isn't exposed
anywhere.
_______________________________________________
dev-embedding mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-embedding
Reply | Threaded
Open this post in threaded view
|

Re: APIs to retrieve font-family information for text nodes in mozilla embed using C++?

L. David Baron
In reply to this post by srivani
srivani wrote:
> Is there any API that I can use on text nodes(of type nsITextContent)
> to get the associated font-family info)?

In addition to what Eli wrote, I'd point out two things:

1) text nodes always have the same style data as their parent element.
In terms of the internal GetStyleData() API, you can get the relevant
style data from either.  In terms of the public/frozen GetComputedStyle
API, you can get it only from the parent element node.  But it's the
same either way.

2) These APIs tell you only what the specified font is; they don't tell
you which fonts were actually used.  (Font selection is effectively
character-by-character, using the list of fonts in the 'font-family'
property.  The first font in the list that is present on the system and
has the character will be used for that character.  But we don't
currently have any API that gives you that information; if we did it
would be useful for other things, though.)

-David

--
L. David Baron                                <URL: http://dbaron.org/ >
            Technical Lead, Layout & CSS, Mozilla Corporation
_______________________________________________
dev-embedding mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-embedding
Reply | Threaded
Open this post in threaded view
|

Re: APIs to retrieve font-family information for text nodes in mozilla embed using C++?

L. David Baron
L. David Baron wrote:
> 1) text nodes always have the same style data as their parent element.
> In terms of the internal GetStyleData() API, you can get the relevant
> style data from either.  In terms of the public/frozen GetComputedStyle
> API, you can get it only from the parent element node.  But it's the
> same either way.

Er, to be a little more precise, that's true only for inherited
properties.  For non-inherited properties, text nodes always have the
default values.  But that's even less interesting.

(See http://developer.mozilla.org/en/docs/CSS:inheritance for the
difference between inherited and non-inherited properties.)

-David

--
L. David Baron                                <URL: http://dbaron.org/ >
            Technical Lead, Layout & CSS, Mozilla Corporation
_______________________________________________
dev-embedding mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-embedding