How to Get Text X, Y position?

B

bapujimoka.dj

Hi All,
I am writing an application which will export power point slide
content into a text file. I am iterating through all shapes and
getting each textRange(from textFrame). From textRange getting text
and font style.Everything is working fine except text x, y position.
To get text X-position i am using text range's BoundLeft function and
for Y-Position I am using text range's BoundTop function. Both
functions are returning value in Points. How to convert this into
pixels? And BoundTop is always returning same value for different
TextRanges(Font and Font size is different). How to get X, Y position
of the each textRange?
 
B

bapujimoka.dj

Pixels where? The value will depend on the resolution of the screen you're
showing the presentation on, so you'd have to call a WinAPI function to get
that info. From there it'd be a relatively simple ratio calculation IF the
slide size and screen size are of the same proportions. Otherwise you'll have
to work out some offsets.


Can you post some example code that demonstrates this?

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Live and in personable in the Help Center at PowerPoint Live
Sept 21-24, San Diego CA, USAwww.pptlive.com

Hi Steve,
Thanks for the reply.I am using C++. My Code is like this..
Sample Code:-
==================
for(int j = 1; j <= totalSlides; j++)
{
CSlide slide = allSlides.Item(COleVariant((long)j));
CShapes shapes = slide.get_Shapes();

int iTotalShapes = shapes.get_Count();
for(int i = 1; i <= iTotalShapes; i++)
{
CShape shape =
shapes.Item(COleVariant((long)i));
CTextFrame textFrame = shape.get_TextFrame();

if(textFrame.get_HasText())
{
CTextRange textRange =
textFrame.get_TextRange();
CTextRange allTextanges = textRange.Runs(1, 9999);
long totalRuns = allTextanges.get_Count();
for (int k = 1; k <= totalRuns; k++)
{
CTextRange eachTextRange = allTextanges.Runs(k, 1);

//get the text
CString strValue =
eachTextRange.get_Text();

//get each text Range left,top, width and height values
float boundLeft = eachTextRange.get_BoundLeft();
float boundTop = eachTextRange.get_BoundTop();
float boundWidth = eachTextRange.get_BoundWidth();
float boundHeight = eachTextRange.get_BoundHeight();
}
}
}
}
====================================
And sample slide image is : http://img57.imageshack.us/img57/5172/ppttestdj6.png
AAAAAA - is of Font Tohoma and font size is 60.
BBBBBB - is of Font Arial and font size is 20.
CCCCCCCCCCCC - is of Font Impact and font size is 54.

First two text are in same line but third text splitted into two line.

I want to know position of each text in Pixels from left edge of the
slide? What I need to do to achieve this?
 
B

bapujimoka.dj

The link to the sample image isn't responding, so I wasn't able to see it so I
created my own example slide. In VBA, this works:

Sub Example()

Dim oSh As Shape
Dim oRun As TextRange

Set oSh = ActiveWindow.Selection.ShapeRange(1)

For Each oRun In oSh.TextFrame.TextRange.Runs
Debug.Print oRun.Text
Debug.Print oRun.BoundLeft
Next

End Sub

Since I couldn't see your sample I'm not sure why the fact that the third sample
is on two lines is relevant. Do you need the Left position for each line?

You could iterate through the Lines collection instead of the Runs collection.

As to number of pixels, it's not a meaningful question unless you specify whether
this is in slide show or some other display mode, and what the resolution of the
monitor is.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Live and in personable in the Help Center at PowerPoint Live
Sept 21-24, San Diego CA, USAwww.pptlive.com

Thanks Steve. If I iterate through the Lines collection, I am able to
get text position. Thank you very much.
I am getting these values in Points. Now I want to convert these
values into Pixels. I am doing entire thing in Normal mode only(Not in
slide show mode). How will I get Screen resolution programatically and
how to convert Points to Pixels with respective to Slide top left
corner?

For Text Y- Position I am taking BoundTop + BoundHeight and X-position
as BoundLeft. Is it correct way?

thanks,
bapu.
 
B

bapujimoka.dj

I think .PointsToScreenPixelsX and .PointsToScreenPixelsY will give you what you're
after.


.PointsToScreenPixelsX gives you the number of pixels relative to the window, I'm
pretty sure. You'll probably need to add then delete a temporary object at the
left/top of the slide to determine how many pixels IT is from the top/left of the
window, then use that value as an offset.





-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Live and in personable in the Help Center at PowerPoint Live
Sept 21-24, San Diego CA, USAwww.pptlive.com

Thanks Steve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top