Re: How to Obtain Text Node Coordinates
- From: "Daniel Mccann" <dmccann_NOSPAM@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 May 2007 15:56:10 -0600
Works like a charm, thanks! The only problem is that I'm a little concerned
about performance in the situations where we have a large number of text
nodes that we need to apply this method to. I'd think there must be some
interface or method that we could use to simply return the coordinates (e.g.
like getBoundingClientRect(), which you can't apply to a text node
directly). Am I just missing something obvious?
"lemax" <lemax@xxxxxx> wrote in message
news:1179996877.835665.65030@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 24, 12:48 am, "Daniel Mccann" <dmccann_NOS...@lde-
innovations.com> wrote:
I need to be able to determine the coordinates of a text node
(IHTMLDOMTextNode), but do not appear to be able to cast it to any
remotely
useful interface whereby I can obtain these coordinates. Does anyone
know
how I can get them?
If there are no interfaces that provide the coordinates, perhaps I can
get
them from the rendering engine.
Any help would be much appreciated!
Thanks,
Dan
It is easy if you you dummy nodes.
Just insert a node like <span> or whatever around it and delete it
after getting the coordinates:
code sample:
CComPtr<IHTMLElement> ptrSpanElement;
CComPtr<IHTMLDOMNode> ptrTextNode; // this is your Textnode you need
the coordinates for
p_ptrNodeToWrap->cloneNode(VARIANT_TRUE,&ptrTextNode);
m_ptrCurrentDocument-
createElement(SysAllocString(L"SPAN"),&ptrSpanElement);if (ptrSpanElement)
{
CComPtr<IHTMLDOMNode> ptrSpanNode;
if (SUCCEEDED(ptrSpanElement.QueryInterface(&ptrSpanNode)))
{
ptrSpanElement->put_id("dummy");
IHTMLDOMNode* ptrTemp = NULL;
ptrSpanNode->appendChild(ptrTextNode,&ptrTemp);
m_ptrCurrentParent-
replaceChild(ptrSpanNode,p_ptrNodeToWrap,&ptrTemp);ptrTemp->Release();
//remove the dummy node
ptrSpanNode->removeNode(VARIANT_FALSE,NULL);
}
}
I hope this helps you out.
Regard,
Thomas
.
- Follow-Ups:
- Re: How to Obtain Text Node Coordinates
- From: lemax
- Re: How to Obtain Text Node Coordinates
- References:
- How to Obtain Text Node Coordinates
- From: Daniel Mccann
- Re: How to Obtain Text Node Coordinates
- From: lemax
- How to Obtain Text Node Coordinates
- Prev by Date: Re: How to Obtain Text Node Coordinates
- Next by Date: Auto-detect RSS/Atom feeds on the browsed webpages
- Previous by thread: Re: How to Obtain Text Node Coordinates
- Next by thread: Re: How to Obtain Text Node Coordinates
- Index(es):