Hello,
I'm new here. Been coding up some stuff to translate diagrams from company XML documents (1000s of them) to Visio. I think I have most of what I need - shapes, connectors, a few rectangles, layers, etc. I've been able to read the xml and drop those items on to a diagram in Visio with good results. What I can't seem to figure out is how to draw free floating text on the diagram. It must be so obvious that I can't see it. Some of the company diagrams have text in different sizes and fonts just placed in random locations around the page.
I have searched for what to do on that but can't find an example. It's difficult to search on 'text' and find anything meaningful since the word is so generic.
Would you mind pointing me in the right direction on how to 'drop' text on a diagram? Any help on this would be appreciated.
Thanks,
spud
A text shape is nothing special, draw a plain rectangle, set the line size to 0 and turn off any fill.
You might want to resize the text area depending upon the size of the text to stop the text from wrapping.
http://www.visguy.com/2009/05/06/top-twelve-text-tips/ (http://www.visguy.com/2009/05/06/top-twelve-text-tips/)
will help.
So, I guess there is no specific 'text' shape. Ok, that was too obvious for me to see that. That should work.
Is there an obvious way to figure out the width an height of the rectangle using the text? What I have is the text and a point size of the text and a font. I'm assuming I'll have to know the font size, the characters I'm using and do some type of text metric to find that out.
Thanks very much,
spud
Quote from: spud on September 22, 2011, 09:27:59 PM
Is there an obvious way to figure out the width an height of the rectangle using the text? What I have is the text and a point size of the text and a font. I'm assuming I'll have to know the font size, the characters I'm using and do some type of text metric to find that out.
Item 6 in the above article.
Ok, excellent. I'll get that going and post my results.
Thanks much for the quick responses,
spud
Well, ok, here's what I was able to come up with and it worked. Don't know if I did any of the assignments into the cells properly but the code will create a line of text on the diagram without the rectangular line and filler. I also colored the text, changed the size, the horizontal alignment and the style. No fonts are specified in the original application, so I'll probably add a font parameter at a later time.
void VisioShapeAgent::DrawText( const _bstr_t & p_textLabel, double p_coords[], const _bstr_t * p_fontColor,
int p_fontSize, const _bstr_t & p_fontType, const _bstr_t & p_textAlign)
{
//creating a zero area rectangle but at intended location, using the same location for x2, y2
IVShapePtr shape = m_VisioApp->ActivePage->DrawRectangle(
p_coords[0],p_coords[1],p_coords[0],p_coords[1]);
//set the text
shape->Text = p_textLabel;
//font size
shape->GetCells("Char.Size")->FormulaU = "\"" + _bstr_t(p_fontSize) + " pt.\"";
//wrap the box around the text
IVCellPtr aCell = shape->GetCellsSRC(visSectionObject,visRowXFormOut,visXFormWidth);
aCell->FormulaU = "\"=GUARD(MAX(TEXTWIDTH(TheText),8*Char.Size))\"";
aCell = shape->GetCellsSRC(visSectionObject,visRowXFormOut,visXFormHeight);
aCell->FormulaU = "\"=GUARD(MAX(TEXTHEIGHT(TheText,Width)))\"";
//Remove rectangular filler
aCell = shape->GetCellsSRC(visSectionFirstComponent,visRowComponent,visCompNoFill);
aCell->FormulaU = "=TRUE";
//Remove the rectangular line
aCell = shape->GetCellsSRC(visSectionFirstComponent,visRowComponent,visCompNoLine);
aCell->FormulaU = "=TRUE";
//Font color
aCell = shape->GetCellsSRC(visSectionCharacter, visRowCharacter, Visio::visCharacterColor);
aCell->FormulaU = "=RGB(" + p_fontColor[0] + "," + p_fontColor[1] + "," + p_fontColor[2] + ")";
//Font type or style: Normal, Italic, Bold, Underline
aCell = shape->GetCellsSRC(visSectionCharacter, visRowCharacter, visCharacterStyle);
VisCellVals fontType = Visio::VisCellVals(0); //Normal; default
if( p_fontType == _bstr_t("Italic") )
{
fontType = VisCellVals::visItalic;
}
else if( p_fontType == _bstr_t("Bold") )
{
fontType = VisCellVals::visBold;
}
else if( p_fontType == _bstr_t("Underline") )
{
fontType = VisCellVals::visUnderLine;
}
aCell->ResultIU = fontType;
//horizontal alignment: Left, Center, Right. Visio has more.
aCell = shape->GetCellsSRC(visSectionParagraph,visRowParagraph,visHorzAlign);
VisCellVals horizontalAlign = Visio::VisCellVals(0); //Left; default
if( p_textAlign == _bstr_t("Center") )
{
horizontalAlign = VisCellVals::visHorzCenter;
}
else if( p_textAlign == _bstr_t("Right") )
{
horizontalAlign = VisCellVals::visHorzRight;
}
aCell->ResultIU = horizontalAlign;
}
Any suggestions for improved value assignment would be appreciated. It is in C++ since the legacy application was done in C++ as well.
Thanks very much for the help!
spud
Browser ID: smf
(is_webkit)
Templates: 1:
Printpage (default).
Sub templates: 4:
init,
print_above,
main,
print_below.
Language files: 1:
index+Modifications.english (default).
Style sheets: 0:
.
Hooks called: 56 (
showintegrate_autoload, cache_get_data, integrate_pre_load, integrate_load_session, integrate_verify_user, cache_get_data, integrate_user_info, integrate_load_board, cache_get_data, integrate_board_info, cache_get_data, integrate_allowed_to_general, integrate_pre_load_theme, cache_get_data, integrate_allowed_to_general, integrate_simple_actions, integrate_allowed_to_general, integrate_load_theme, integrate_pre_log_stats, cache_get_data, integrate_actions, integrate_pre_parsebbc, integrate_bbc_codes, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_menu_buttons, integrate_current_action, integrate_theme_context, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general)
Files included: 25 - 925KB. (
show/home/iw0lkfe3x6cq/public_html/vgforum/index.php, /home/iw0lkfe3x6cq/public_html/vgforum/Settings.php, /home/iw0lkfe3x6cq/public_html/vgforum/cache/db_last_error.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/QueryString.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Auth.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Errors.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Load.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Security.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Compat.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Db-mysql.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApi.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApiInterface.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/APIs/FileBased.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Charset.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/Metadata.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/QuickCheck.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Session.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Logging.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Class-BrowserDetect.php, (Current Theme)/languages/index.english.php, (Current Theme)/languages/Modifications.english.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Printpage.php, (Current Theme)/Printpage.template.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/CaseUpper.php)
Memory used: 764KB.
Tokens:
post-login.
Cache hits: 7: 0.00121s for 22,302 bytes (
showget modSettings: 0.00060s - 19983 bytes, get known_languages: 0.00022s - 1277 bytes, get board_parents-0: 0.00010s - 2 bytes, get permissions:-1: 0.00008s - 50 bytes, get theme_settings-1: 0.00009s - 980 bytes, get log_online-update: 0.00009s - 10 bytes, get menu_buttons--1-english: 0.00004s - 0 bytes)
Cache misses: 1: (
showget menu_buttons--1-english)
Queries used: 9.
[Show Queries]